闭包:
var extent = (function(){
var value = 0;
return {
call: function() {
value++;
console.log(value);
}
}
})();
extent.call(); // 1
extent.call(); // 2
extent.call(); // 3
面向对象:
var extent = {
value: 0,
call: function() {
this.value++;
console.log(this.value);
}
}
var Extent = function() {
this.value = 0;
}
Extent.prototype.call = function() {
this.value++;
console.log(this.value);
}
var extent = new Extent();
网友评论