- 相關(guān)推薦
javascript面向對象中的對象怎么理解
javacript面向對象程序設計中,可以理解為一切都是對象。實(shí)例代碼如下:
復制代碼 代碼如下:
function Cat(){
}
var cat1 = new Cat();//創(chuàng )建類(lèi)實(shí)例
cat1.name = "小狗";
cat1.age = 4;
cat1.color="白色";
document.write(cat1.name);
document.writeln(cat1.constructor);//實(shí)例化后對象,是對象
document.writeln(typeof(cat1)+"
");
document.writeln(Cat.constructor);//原型對象本身也是對象
document.writeln(typeof Cat+"
");
var b="hello";//字符串也是對象
document.writeln(b.constructor);//輸出它的構造函數
document.writeln(typeof b+"
");
var c=123;//數值也是對象
document.writeln(c.constructor);
document.writeln(typeof c+"
");
判斷一個(gè)實(shí)例化對象是不是某個(gè)原型對象類(lèi)型
復制代碼 代碼如下:if(cat1 instanceof Cat){//與php的判斷方法相同
window.alert("ok");
}
希望本文所述對大家的javascript程序設計有所幫助。
【javascript面向對象中的對象怎么理解】相關(guān)文章:
JavaScript中的三種對象04-01
javascript克隆對象深度介紹03-31
Javascript中arguments對象的詳解和使用方法03-31
關(guān)于javascript對象之內置和對象Math的使用方法03-30
JAVA面向對象的三大特性02-26
JavaScript高級程序設計:本地對象Array03-29
對javascript的理解03-29
PHP面向對象重載重寫(xiě)的不同04-03