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

 

 
 

转载于:https://www.cnblogs.com/dorothyorsusie/p/6179178.html

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐