ReferenceError: “alert” is not defined

用Node.js单独运行js文件时,其中定义的alert不可用

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

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”。

 

 
 
posted @ 2016-12-14 14:27  dorothyorsusie  阅读(3149)  评论(0编辑  收藏  举报