- 相關(guān)推薦
javascript面向?qū)ο笾械膶ο笤趺蠢斫?/p>
javacript面向?qū)ο蟪绦蛟O(shè)計中,可以理解為一切都是對象。實例代碼如下:
復(fù)制代碼 代碼如下:
function Cat(){
}
var cat1 = new Cat();//創(chuàng)建類實例
cat1.name = "小狗";
cat1.age = 4;
cat1.color="白色";
document.write(cat1.name);
document.writeln(cat1.constructor);//實例化后對象,是對象
document.writeln(typeof(cat1)+"
");
document.writeln(Cat.constructor);//原型對象本身也是對象
document.writeln(typeof Cat+"
");
var b="hello";//字符串也是對象
document.writeln(b.constructor);//輸出它的構(gòu)造函數(shù)
document.writeln(typeof b+"
");
var c=123;//數(shù)值也是對象
document.writeln(c.constructor);
document.writeln(typeof c+"
");
判斷一個實例化對象是不是某個原型對象類型
復(fù)制代碼 代碼如下:if(cat1 instanceof Cat){//與php的判斷方法相同
window.alert("ok");
}
希望本文所述對大家的javascript程序設(shè)計有所幫助。
【javascript面向?qū)ο笾械膶ο笤趺蠢斫狻肯嚓P(guān)文章:
Word快速提取對象文件技巧03-16
javascript跨域訪問的方法07-19
演講中的故事應(yīng)該怎么講02-11
CAD中怎么設(shè)置標(biāo)注樣式與比例07-17
EXCEL表格中數(shù)據(jù)透視表怎么用05-24
在excel表格中怎么設(shè)置水平垂直居中對齊?04-13
CAD中怎么等分一條直線或曲線07-17