function Person(name) { this.name = name; this.say = function() { console.log(this.name) } }
等价于
function Person(name) { this.name = name; } Person.prototype.say = function() { console.log(this.name); }
静态类
var objName = { name:"name", funcName: function() { alert(this.name); } } //调用 objName.funcName();
类
function objName(name) { this.name = name; this.funcName = function() { alert(this.name); } } 等价于 var objNmae = function(name) { this.name = name; this.funcName = function() { alert(this.name); } } //调用 var obj = new objName("test"); obj.funcName();
时间: 2024-11-04 20:20:32