-
严格模式下,apply第一参数为null/undefined,this指向null/undefined查看全部
-
apply第一个参数为null/undefined,this对象指向global object(window in browser)查看全部
-
z没有传进去,设定arguments也无用查看全部
-
toString和valueOf把一个逻辑值转换为字符串,并返回结果查看全部
-
extensible标签:查看全部
-
对象标签: [[proto]]:原型链 [[class]]:toString [[extensible]]:表示对象的属性是否可以添加。 object.preventExtensible(obj);//使obj对象不可新增属性,原属性可改、可删 Object.seal(obj);//使obj不可新增属性,原属性可改但不可删 Object.freeze(obj);//使obj不可新增属性,原属性不可更改、删除 注意,当Object.freeze(obj)后,Object.isSeal(obj)返回的也是true,也就是说,Object.isSeal(obj)返回true,其原属性也可能不可改。查看全部
-
function查看全部
-
属性标签查看全部
-
<script> // Object.getOwnPropertyDescriptor({pro:true},'pro'); var person = {}; Object.defineProperty(person,'name',{value:'snow',writable:false,configurable:false,enumerable:true});//给对象添加属性name; console.log(person.name); person.name = 'rain'; console.log(person.name); delete person.name; Object.defineProperty(person,'type',{value:'object1',writable:true,configurable:true,enumerable:false}); Object.keys(person); //["name"] 没有type,因为枚举属性enumerable是false </script>查看全部
-
对象属性: writable是否可写 ;enumerable:是否可遍历,枚举,影响for in中是否会出现;configurable:是否暂被修改,可删除查看全部
-
<script type="text/javascript"> var o = {}; Object.defineProperty(o,'x',{value:1}); //writable = false, configurable = false var obj = Object.create(o); console.log(obj.x); //1 obj.x = 200; // writable = false, 时不能修改x的值; console.log(obj.x); //1 Object.defineProperty(obj,'x',{value:100,writable:true,configurable:true}); //覆盖掉原形链上不可写的x的值; console.log(obj.x); //100 obj.x = 500; //500 console.log(obj.x); //500 </script>查看全部
-
<script type="text/javascript"> function foo() {} Object.defineProperty(foo.prototype,'z',{get:function () { return 1; }}); var obj = new foo(); console.log(obj.z); //1 obj.z = 10; //原形链上有get方法时,不能设置原形链上的z的值 console.log(obj.z); //1 Object.defineProperty(obj,'z',{value:100,configurable:true}); //在obj上设置z;configurable:true使得z可以在后面被删除; console.log(obj.z); //100 delete obj.z; //删除z console.log(obj.z); //1 </script>查看全部
-
<script type="text/javascript"> var man = { weibo:'@bosn', $age:null, get age(){ if(this.$age==undefined){ return new Date().getFullYear()-1987; } else{ return this.$age; } }, set age(val){ val=+val; //把val变为数字形式; if(!isNaN(val)&&val>0&&val<150){ //如果val存在,且大于0,小于150 this.$age= +val; //把val变为数字复制给$val } else{ throw new Error('Incorrect val = '+val); //否则抛出异常; } } }; console.log(man.age); //30 man.age = 100; console.log(man.age); //100 man.age ='abc'; //Uncaught Error: Incorrect val = NaN </script>查看全部
-
<script type="text/javascript"> var man = { name:'bosn', weibo:'@bosn', get age(){ return new Date().getFullYear()-1987; }, set age(val){ console.log('Age can\'t be set to'+val); } }; console.log(man.age); //30 man.age=100; //Age can't be set to100 console.log(man.age); //30 </script>查看全部
-
prototype是函数对象默认就会有一个对象属性。本身也是对象,它的作用是:作为通过new 构造函数调用时产生的对象的原型。JS是基于原型链继承的 读写异常处理:常用if判断是否为空,或者通过&&的方式处理读写异常。 原型、全局变量、局部变量、函数均不允许删除,每个属性有一系列的标签来控制权限。比如configurable。 检测是否对象上是否存在一个属性: 1、in 查找:会像原型链上查找 2、hasOwnProperty 查找对象本身的属性 delete不表示操作成功,而是说明要删除的对象已经不存在了 var yz=obj&&obj.y&&obj.y.z; //返回obj.y.z的值或undefined; 获取对象上某个属性的配置标签信息: var descriptor=Object.getOwnPropertyDescriptor(Object,"prototype"); descriptor.configurable;//false var cat=new Object; cat.legs=4; cat.name="Kitty"; 'legs' in cat;//true 'abc' in cat;//false 'toString' in cat;//true .inherited property!!!!!!! cat.hasOwnProperty("legs");//true cat.hasOwnProperty("toString");//false //propertyIsEnumerable()检查是否可被枚举的。属性是否会出现在for in 中 cat.propertyIsEnumerable("legs");//true cat.propertyIsEnumerable("toString");//false defineProperty定义对象属性时,枚举等标签默认都是false Object.defineProperty(cat,"price",{enumerable:false,value:1000}); cat.propertyIsEnumerable("price");//false cat.hasOwnProperty("price");//true查看全部
举报
0/150
提交
取消