ES5中prototype的應(yīng)用, 在JS中,函數(shù)同時(shí)也是一個(gè)對(duì)象, 向這個(gè)函數(shù)對(duì)象中添加屬性及函數(shù)可使用prototype這個(gè)屬性
<script type="text/javascript">
function Obj(){
this.name ="南昌雅騰";
this.success = function(){
console.log('成功');
}
}
Obj.prototype.address = "南昌艾溪湖邊上";
Obj.prototype.getName = function(){
return this.name;
}
var app = new Obj();
console.log(app.getName());
</script>