閉包:
var extent = (function(){
var value = 0;
return {
call: function() {
value++;
console.log(value);
}
}
})();
extent.call(); // 1
extent.call(); // 2
extent.call(); // 3
面向?qū)ο螅?/h2>
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();
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();