ReferenceError: 「alert」 is not defined

用Node.js單獨運行js文件時,其中定義的alert不可用web

alert is not part of JavaScript, it's part of the window object provided by web browsers. ide

var name = "The Window";

function ttt() {

return(this.name);
}
alert(ttt.call(window);
//alert(window);

var object = {

name : "My Object",
getNameFunc : function(){

return function(){

return this.name;
};
}};

console.log(object.getNameFunc()()); // console The Windowvar name = "The Window";

var object = {
name : "My Object",
getNameFunc : function(){
var that = this;
return function(){
return that.name;
};
}};

console.log(object.getNameFunc()()); //console My Object
 
     
 
     
若是是在Node.js中運行的話,window會提示「undedined」。
相關文章
相關標籤/搜索