var timestamp = function(){ var timestamp = Date.parse(new Date()); return timestamp/1000;
}();
var timestamp = Date.parse(new Data()); timestamp = timestamp/1000;
看上去好像比上面的操做簡潔多了,只須要兩行代碼。可是咱們仔細去觀察,就會發現第一段代碼其實自己僅是一個賦值操做,在function中完成的全部動做將會在function執行完後所有釋放,整個代碼看上去好像只執行了一條語句同樣。函數
而實際上更重要的意義在於它能夠讓一個變量在初始化時,就具有了運算結果的效果。this
var person = new function(){對象
var name = '小明';原型
this.speak = function(age){io
console.log(name + '已經' + age + '歲了');console
}function
}變量
person.speak(11);im
此時的new裏面的this是指向使用的本身co
var message = new Function('msg','alert(msg)');
至關於
function message(msg) {
alert(msg);
}