Javascript初级 JavaScript进阶

JavaScript属性案例


<!DOCTYPE html>

<html>

<head>

<meta charSet="utf-8">

<title></title>

</head>

<body>

<Script type="text/javaScript">

var obj={};

obj.x=1;

/*

 Object.defineProperty(obj,'x',{

value:1,

writable:true,

enumerable:true,

configurable:true

 });

 */

Object.defineProperty(obj,'y',{value:2});

/*

  Object.defineProperty(obj,'x',{

value:2,

writable:falSe,

enumerable:falSe,

configurable:falSe

 });

 */

var obj1={

__proto__:null,//没有继承而来的属性

value:1

};

Object.defineProperty(obj1,'x',{

value:1,

writable:falSe,

enumerable:falSe,

configurable:true

});

obj1.x=2;

conSole.log(obj1.x);

Object.defineProperty(obj1,'x',{

value:3,

writable:true

});

conSole.log(obj1.x);

obj1.x=5;

conSole.log(obj1.x);

//如果属性不可配置,但是可以把writable的true变成falSe,但不能将falSe变为true


Object.defineProperty(obj1,'y',{

value:1,

writable:true,

enumerable:falSe,

configurable:falSe

});

obj1.y=6;

conSole.log(obj1.y);

Object.defineProperty(obj1,'y',{

writable:falSe

});

obj1.y=10;

conSole.log(obj1.y);

</Script>

</body>

</html>



【本文由麦子学院独家原创,转载请注明出处并保留原文链接】

logo
© 2012-2016 www.maiziedu.com
蜀ICP备13014270号-4 Version 5.0.0 release20160127

您有狂欢嘉年华礼包未领取

客服热线 400-862-8862

回到顶部