fn.call(o); //改變函數fn的作用域對象
fn.apply(o); //改變函數fn的作用域對象
fn.bind(o); //將函數fn的作用域綁定到對象o上
fn.apply(o); //改變函數fn的作用域對象
fn.bind(o); //將函數fn的作用域綁定到對象o上
2018-04-25
定義函數的三種形式:
1,函數聲明
function fn(){}
2,函數表達式
var fn = function(){};
3,函數對象
var fn = new Function('a', 'b', 'return a + b');
1,函數聲明
function fn(){}
2,函數表達式
var fn = function(){};
3,函數對象
var fn = new Function('a', 'b', 'return a + b');
2018-04-25
1,a.concat();
2,a.join();
3,a.reverse();
4, a.sort();
5, a.slice();
6, a.splice();
7, a.valueOf();
8, a.toString();
9, a.indexOf();
10, a.lastInexOf();
11, a.every();
12, a.some();
13, a.filter();
14, a.map();
15, a.forEach();
2,a.join();
3,a.reverse();
4, a.sort();
5, a.slice();
6, a.splice();
7, a.valueOf();
8, a.toString();
9, a.indexOf();
10, a.lastInexOf();
11, a.every();
12, a.some();
13, a.filter();
14, a.map();
15, a.forEach();
2018-04-25
1, Object.preventExtensions(o);
2, Object.seal(o);
3, Object.freeze(o);
4, Object.isExtensible(o);
5, Object.isSealed(o);
6, Object.isFrozen(o);
2, Object.seal(o);
3, Object.freeze(o);
4, Object.isExtensible(o);
5, Object.isSealed(o);
6, Object.isFrozen(o);
2018-04-23
var person = {name: 'zhao', salary: 2000};
Object.defineProperty(person, promote, {
set: function(level){this.salary *= 1 + 0.001*level;}
});
測試:
person.promote = 10; //工作十年,升到第十級
alert(person.salary); //工資漲到2020元
Object.defineProperty(person, promote, {
set: function(level){this.salary *= 1 + 0.001*level;}
});
測試:
person.promote = 10; //工作十年,升到第十級
alert(person.salary); //工資漲到2020元
2018-04-23
1, Object.getOwnPropertyDescriptor(o1, 'name'); //取得屬性的特性
2, Object.defineProperty(o1, 'name', {value: 'zhao', enumerable: true, writable: true, configurable: true}); //定義一個屬性
3, Object.getOwnPropertyDescriptors(o1); //取得所有屬性的特性
4, Object.defineProperties(o1, oooo); //定義多個屬性
2, Object.defineProperty(o1, 'name', {value: 'zhao', enumerable: true, writable: true, configurable: true}); //定義一個屬性
3, Object.getOwnPropertyDescriptors(o1); //取得所有屬性的特性
4, Object.defineProperties(o1, oooo); //定義多個屬性
2018-04-23
var book = {
editor: 0,
_year: 2015,
get year(){
return this._year;
}
set year(y){
if(y < this._year){
alert('Incorrect year');
}
else{
this._year = y;
this.editor = y - this._year;
}
}
}
}
}
}
}
}
}
};
editor: 0,
_year: 2015,
get year(){
return this._year;
}
set year(y){
if(y < this._year){
alert('Incorrect year');
}
else{
this._year = y;
this.editor = y - this._year;
}
}
}
}
}
}
}
}
}
};
2018-04-23