當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS prototype作用
生活随笔
收集整理的這篇文章主要介紹了
JS prototype作用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?prototype可查看原型屬性,還可對原型添加屬性或方法
function Car(name) {this.name = name;this.run = function () {console.log(this.height+'cm '+this.name + 'is run!')}}var dazhong = new Car('dazhong');Car.prototype.height = null; //給對象添加新屬性dazhong.height = 200 //給屬性賦值dazhong.run(); //調用run方法打印console.log(Car.prototype) //prototype不僅能在原型對象上添加屬性或方法,還可查看原型屬性現在我們打印dazhong;
console.log(dazhong.prototype)發現沒有prototype這個屬性,我們可以用__proto__這個非標準用法來查看這個對象的屬性
總結
以上是生活随笔為你收集整理的JS prototype作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx下配置小绿锁https
- 下一篇: gradle idea java ssm