面向?qū)ο?

一、構(gòu)造函數(shù)

var mrZhang = {
  name:"zhangsan",
  sex:"男",
  age:24,
  healthy:100,
  smoke:function(){
    console.log("I am smoking");
    this.healthy --;
  },
  drink:function(){
    console.log("I am drinking");
    this.healthy ++;
  }
}
//誰觸發(fā)的事件,this就指向誰
//這個(gè)方法屬于誰的,this就指向誰

對(duì)象的創(chuàng)建方法
var obj = {} plainObject 對(duì)象的字面量/對(duì)象直接量
構(gòu)造函數(shù)
系統(tǒng)定義:new Object()
自定義:(大駝峰式寫法:AaaBbbCcc、小駝峰式寫法:aaaBbbCcc)
function AaaBbbCcc(){ //構(gòu)造函數(shù)
}
var a = new abc() //實(shí)例化

function Car(color){
  this.color = color;
  this.name = "BAOMA";
  this.height = 1600;
  this.weight = 1000;
  this.healthy = 100;
  this.run = function(){
    this.healthy --;
  }
}

var car1 = new Car("red");
var car2 = new Car("black");

二、包裝類

var num = 123;
num.add = 4;
//new Number(num).add = 4; delete
console.log(num.add);

var str = "string";
str.length = 2;
//new String("string").length = 2;  delete
console.log(str.length);

var arr = [1, 2, 3, 4, 5, 6];
arr.length = 2;

例子:

var str = "123";
str += 1;
var test = typeof(str); //test == "string";
if(test.length == 6){
  test.sign = "typeof的返回結(jié)果可能為String";  //delete
}
console.log(test.sign);
var x = 1, y = z = 0;
function add(n){
  return n = n + 1;
}
y = add(x);
function add(n){
  return n = n +3;
}
z = add(x);
console.log(x, y, z);
//下面的代碼中console.log的結(jié)果是[1, 2, 3, 4, 5]的選項(xiàng)是
//A
function foo(x){
  console.log(arguments);
  return x;
}
foo(1, 2, 3, 4, 5);

//B
function foo(x){
  console.log(arguments);
  return x;
}(1, 2, 3, 4, 5)

//C
(function foo(x){
  console.log(arguments);
  return x;
})(1, 2, 3, 4, 5)
typeof可能返回的結(jié)果是
1.Number
2.String
3.Array
4.Boolean
5.Object
6.function
7.null
8.undefined

124568
//下面alert的結(jié)果是什么
function a(x, y, z){
  arguments[2] = 4;
  alert(z);
}
a(1, 2, 3);

function a(x, y, z){
  z = 4;
  alert(arguments[2]);
}
a(1, 2, 3);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容