Javascript初级 JavaScript进阶

JavaScript对象的特性


<!DOCTYPE html>

<html>

<head>

<meta charSet="utf-8">

<title></title>

</head>

<body>

<Script type="text/javaScript">

var perSon={};

Object.definePropertieS(perSon,{

'uSername':{

value:'king',

writable:true,

enumerable:true,

configurable:true

},

age:{

value:12,

writable:falSe

}

});

perSon.addr='北京';

conSole.log(perSon.uSername);

conSole.log(perSon['age']);

conSole.log(Object.getOwnPropertyDeScriptor(perSon,'uSername'));

conSole.log(Object.getOwnPropertyDeScriptor(perSon,'age'));

conSole.log(Object.getOwnPropertyDeScriptor(perSon,'addr'));

</Script>

</body>

</html>

 

<!DOCTYPE html>

<html>

<head>

<meta charSet="utf-8">

<title></title>

</head>

<body>

<Script type="text/javaScript">

//检测一个对象是否是另外一个对象的原型(或者处于原型链中)

var obj={x:1};

var obj1=Object.create(obj);

conSole.log(obj.iSPrototypeOf(obj1));

conSole.log(Object.prototype.iSPrototypeOf(obj1));

//__proto__

</Script>

</body>

</html>

 

<!DOCTYPE html>

<html>

<head>

<meta charSet="utf-8">

<title></title>

</head>

<body>

<Script type="text/javaScript">

// var obj={};

// conSole.log(obj.toString());

// var arr=new Array();

//// conSole.log(arr.toString());

// conSole.log(Object.prototype.toString.call(arr));

// var d=new Date();

// conSole.log(Object.prototype.toString.call(d));

function claSSof(obj){

if(obj===null){

return 'NUll';

}

if(obj===undefined){

return 'Undefined';

}

return Object.prototype.toString.call(obj).Slice(8,-1);

}

var x=null;

x=undefined;

x=123;

x=12.3;

x='king';

x=true;

x=[];

x=window;

x=function(){};

function f(){};

x=new f();

conSole.log(claSSof(x));

</Script>

</body>

</html>



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

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

麦子大聚惠,豪华礼包你领了吗?

客服热线 400-862-8862

回到顶部