Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

关于内部函数调用对象的问题

function Person(name){
    var name=name;
    function getName(){
        return name;
    }
    getName();
}
Person("Nicholas");
在全局作用域中,调用Person("Nicholas")对象是window,那么在Person函数的内部,
调用getName()函数的对象该是谁呢???

补充:
 function Person(name){
    var name=name;
    function getName(){
        alert(name);
    }
    window.getName();//window.getName is not a function 
}
Person("Nicholas");

在这段代码中,我用window调用getName()方法,会报错!window.getName is not afunction ???这是否能够说明,window不能调用该方法呢??


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

还是window


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...