-
Notifications
You must be signed in to change notification settings - Fork 896
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
写出输出结果 #213
Labels
Comments
Foo.getName() |
function Foo() {
getName = function () {
alert(1);
};
return this;
}
// 定义了Foo构造函数,new的实例拥有getName方法,提示1
var getName;
// window中定义getName,开辟栈
function getName() {
alert(5);
}
// window中的getName定义为一个提示5的方法
Foo.getName = function () {
alert(2);
};
// 定义Foo类的静态方法getName,提示2
Foo.prototype.getName = function () {
alert(3);
};
// 更改Foo原型的getName,现在new的实例getName提示3
getName = function () {
alert(4);
};
// window中的getName方法改为提示4
Foo.getName(); // ?
// 调用Foo类的静态方法,提示2
getName(); // ?
// 调用window的getName方法,提示4
Foo().getName(); // ?
// 先调用Foo,是window调用的,将window的getName改为提示1
// 返回window
// window调用getName,提示1
getName(); // ?
// 调用window的getName,提示1
new Foo.getName(); // ?
// Foo类的静态方法,提示2,返回一个空实例
new Foo().getName(); // ?
// 新建Foo实例,调用实例的getName,提示3
new new Foo().getName(); // ?
// 新建Foo实例,新建实例getName构造的实例,提示3,返回空实例 按顺序提示
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: