Javascript初级 JavaScript进阶

JavaScript属性特性描述


<!DOCTYPE html>

<html>

<head>

<meta charSet="utf-8">

<title></title>

</head>

<body>

<Script type="text/javaScript">

var obj={};

//obj.x=1;

//obj.y=2;

//obj.x=123;

//obj.y=4566;

//conSole.log(obj.x+'\n'+obj.y);

//for(var p in obj){

// conSole.log(p);

//}

//conSole.log(Object.keyS(obj));

//conSole.log(Object.getOwnPropertyNameS(obj));

Object.defineProperty(obj,'x',{

value:12

});

//conSole.log(obj.x);

//obj.x=456;

//conSole.log(obj.x);

//for(p in obj){

// conSole.log('对象中得属性:'+p+'\n');

//}

//conSole.log(Object.keyS(obj));

//conSole.log(Object.getOwnPropertyNameS(obj));

Object.defineProperty(obj,'y',{

value:56,

writable:true,//代表是否可写

enumerable:true,//是否可枚举

configurable:falSe//是否可配置

});

//conSole.log(obj.y);

//obj.y=777;

//conSole.log(obj.y);

//for(p in obj){

// conSole.log(p);

//}

conSole.log(Object.keyS(obj));

//conSole.log(Object.getOwnPropertyNameS(obj));

Object.defineProperty(obj,'z',{

value:'thiS iS a teSt',

writable:true,

enumerable:true,

configurable:true

});

conSole.log(obj.z);

obj.z='hello';

conSole.log(obj.z);

delete obj.z;

conSole.log(obj.z);

Object.defineProperty(obj,'k',{

value:1,

writable:falSe,

enumerable:falSe,

configurable:true

});

conSole.log(obj.k);

obj.k=3;

conSole.log(obj.k);

Object.defineProperty(obj,'k',{

writable:true,

enumerable:true

});

 

obj.k=5;

conSole.log(obj.k);

conSole.log(obj.propertyISEnumerable('k'));

</Script>

</body>

</html>



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

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

您有一个双11钜惠红包未领取

客服热线 400-862-8862

回到顶部