本文進(jìn)一步分析講述了javascript面向?qū)ο笾畬?duì)象的深入理解。分享給大家供大家參考。具體分析如下:
javacript面向?qū)ο蟪绦蛟O(shè)計(jì)中,可以理解為一切都是對(duì)象。實(shí)例代碼如下:
var cat1 = new Cat();//創(chuàng)建類實(shí)例
cat1.name = "小狗";
cat1.age = 4;
cat1.color="白色";
document.write(cat1.name);
document.writeln(cat1.constructor);//實(shí)例化后對(duì)象,是對(duì)象
document.writeln(typeof(cat1)+"<hr />");
document.writeln(Cat.constructor);//原型對(duì)象本身也是對(duì)象
document.writeln(typeof Cat+"<hr />");
var b="hello";//字符串也是對(duì)象
document.writeln(b.constructor);//輸出它的構(gòu)造函數(shù)
document.writeln(typeof b+"<hr />");
var c=123;//數(shù)值也是對(duì)象
document.writeln(c.constructor);
document.writeln(typeof c+"<hr />");
</script>
判斷一個(gè)實(shí)例化對(duì)象是不是某個(gè)原型對(duì)象類型
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選