欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript中Boolean對象的屬性解析

 更新時(shí)間:2015年10月21日 17:47:36   投稿:goldensun  
這篇文章主要介紹了JavaScript中布爾對象的屬性解析,包括對constructor屬性和prototype構(gòu)造器的簡單介紹,需要的朋友可以參考下

constructor 屬性

實(shí)例
返回通過 myvar 對象的原型創(chuàng)建的函數(shù):

var myvar = new Boolean(1);
myvar.constructor;


結(jié)果輸出:

function Boolean() { [native code] }

定義和用法
constructor 屬性返回對創(chuàng)建此對象的 Boolean 函數(shù)的引用。


prototype 構(gòu)造器
為 Boolean 對象創(chuàng)建一個(gè)新的方法:

Boolean.prototype.myColor=function()
{
if (this.valueOf()==true)
 {
 this.color="green";
 }
else
 {
 this.color="red";
 }
}

創(chuàng)建一個(gè) Boolean 對象, 并添加 myColor 方法:

var a=new Boolean(1);
a.myColor();
var b=a.color;


b 結(jié)果輸出:

green

定義和用法
prototype 屬性使您有能力向?qū)ο筇砑訉傩院头椒ā?br /> 當(dāng)構(gòu)造一個(gè)原型,所有的布爾對象默認(rèn)都添加了屬性或方法。
注意: Prototype是一個(gè)全局屬性,這對于幾乎全部的JavaScript對象。

相關(guān)文章

最新評論