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

掉坑的题 #4

Open
amandaXCY opened this issue Jan 26, 2018 · 0 comments
Open

掉坑的题 #4

amandaXCY opened this issue Jan 26, 2018 · 0 comments

Comments

@amandaXCY
Copy link
Owner

function Foo() {
    getName = function () { alert (1); };
    return this;
}
Foo.getName = function () { alert (2);};
Foo.prototype.getName = function () { alert (3);};
var getName = function () { alert (4);};
function getName() { alert (5);}
 
//请写出以下输出结果:
Foo.getName();
getName();
Foo().getName();
getName();
new Foo.getName();
new Foo().getName();
new new Foo().getName();

Wscats/articles#85

综合考核变量提升,this指针指向、运算符优先级、原型、继承、全局变量污染、对象属性及原型属性优先级等知

函数表达和函数声明式

  • 函数声明会被提升到作用域的最前面,即使写代码的时候是写在最后面,也还是会被提升至最前面
  • 而用函数表达式创建的函数是在运行时进行赋值,且要等到表达式赋值完成后才能调用
getName()//oaoafly
var getName = function() {
	console.log('wscat')
}
getName()//wscat
function getName() {
	console.log('oaoafly')
}
getName()//wscat

分解过来就是

var getName
function getName() {
	console.log('oaoafly')
}
getName = function() {
	console.log('wscat')
}

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

No branches or pull requests

1 participant