Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS 作用域、原型链 #26

Open
RookieDay opened this issue Jan 6, 2017 · 3 comments
Open

JS 作用域、原型链 #26

RookieDay opened this issue Jan 6, 2017 · 3 comments

Comments

@RookieDay
Copy link

在社区发现一道题,已授权,在此分享给大家,随后附作者链接,有什么问题还望指正: ^_^

function Foo() {
    getName = function () { 
    	console.log('1');
    };
    return this;
}
Foo.getName = function () {
	console.log('2');
};
Foo.prototype.getName = function () { 
	console.log('3');
};
var getName = function () { 
	console.log('4');
};
function getName() { 
	console.log(5);
}

Foo.getName();  
getName();	
Foo().getName(); 
getName();  
new Foo.getName(); 
new Foo().getName();   
new new Foo().getName();		

请问上述代码在浏览器环境下,输出结果是多少?

@FrankFang FrankFang changed the title Js 作用域、原型链 JS 作用域、原型链 Jan 11, 2017
@RookieDay
Copy link
Author

@t759239391
新年快快乐.....^_^
题目来自cnode社区,这里是详细解答,有什么问题还望指正。
https://cnodejs.org/topic/5867d50d5eac96bb04d3e302

@yxbysxcoco
Copy link

这题也太真实了[joy]

@ThenMorning
Copy link

Foo().getName();
getName();

有意思

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants