function add() {
var count = 0;
function demo() {
count ++;
console.log(count);
}
return demo;
}
var counter = add();
counter();
counter();
複製代碼
function eater() {
var food = '';
var obj = {
eat: function() {
console.log('i am eating' + ' ' + food);
food = '';
},
push: function(myFood) {
food = myFood;
}
}
}
var eater1 = eater();
eater.push('banana');
eater.eater();
複製代碼
function Hang(name, wife) {
var prepareWife = 'xiaozhang';
this.name = name;
this.wife = wife;
this.divorce = function() {
this.wife = prepareWife;
}
this.changePrepareWife = function(target) {
prepareWife = target;
}
this.sayPrepareWife = function() {
console.log(prepareWife);
}
}
var deng = new Hang('deng', 'xiaoliu');
deng.prepareWife;
deng.sayPrepareWife();
複製代碼
function bar() {
say = 'hehe';
}
即==
function bar() {
window.say ='hehe';
}
複製代碼
function foo() {
this.name = 'hehe';
}
foo();
複製代碼
var arr = [1, 2, 3];
arr = null;
複製代碼
const vm = new WeakMap();
const element = document.getElementById('example');
vm.set(element, 'something');
vm.get(element);
複製代碼
var a = new Object();
var b = a;
a = null;
b = null;
複製代碼