文档介绍:Function1:
这是一个很重要的改动,现在我们终于可以得到一个原型链干净的对象了。以前要创建一个类:
functionCat(name){
=name;
=4;
Function1:
这是一个很重要的改动,现在我们终于可以得到一个原型链干净的对象了。以前要创建一个类:
functionCat(name){
=name;
=4;
=false;
=[];
}
={
constructor:Cat,
play:function(){=true;return'playing!';},
feed:function(food){(food);=false;},
speak:function(){return'Meow';}
};
必须要分两步走,但是现在可以不必了:
varDog={
name:'dog',
paws:4,
hungry:false,
eaten:null,
play:function(){=true;return'playing!';},
speak:function(){return'Woof!';}
};
vardog=(Dog);
,是一个propertiesdescriptorobject,关于这方面的详细解释,请看第2点。
另外,,可以用这种方法代替:
if(!=='function'){
=function(o){
functionF(){}
=o;
returnnewF();
};
}
BrowserSupport:
○ Firefox4
○ InternetExplorer9
○ Safari5
○ Chrome5+
Function2:
如果你想为一个对象定义属性,=2;用这种方法。但是在ECMAScript5中,
Parameters:
修饰对象中的定义如下:
● value:.
● writable:usethisbooleantodefinewhetherthisisaread-’swritable,it’.
● configurable:usethisbooleantodefinewhetherthetype()ofthispropertycanbechanged,’sconfigurable,it’.
● enumerable:usethisbooleantodefinewhetherthispropertyisincludedwhenthepropertiesoftheobjectareenumerated(afor-inlooporthekeysmethod).Defaultstofalse.
● get:.
● set:.
示例:
varDog={
name:'dog',
paws:4
};
vardog=(Dog);
(dog,'age',{
set:function(age){=age*7;},
get:function(){;},
enumerable:true
});
=2;
;//1