ES5中prototype的應(yīng)用, 在JS中,函數(shù)同時也是一個對象, 向這個函數(shù)對象中添加屬性及函數(shù)可使用prototype這個屬性
<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>