87,984
社区成员
发帖
与我相关
我的任务
分享
var name = "Robben";
console.info(name);
console.info(this.name);
function Demo(){
this.name = "Robben in object";
var name = "Robben in local";
console.info(name);
console.info(this.name);
}
object = new Demo();
object = new Demo();
Demo();Object obj = new Object();
this = obj;
this = window;function Demo(){
this.name = "Robben in object";
var name = "Robben in local";
this.sayHello1 = function() {
console.info(this.name);
}
this.sayHello2 = function() {
console.info(name);
}
}
object = new Demo()
object.sayHello1();
object.sayHello2();
name = "Robben";
function Demo() {
var name = "Robben in local";
this.name = "Robben in object";
this.sayHello1 = function() {
console.info(name);
}
this.sayHello2 = function() {
console.info(this.name);
};
this.sayHello3 = function() {
return (function(){console.info(this.name);})();
}
}
Demo.name = "Robben in classlike object"; //真不巧,函数有个默认的只读name属性,属性值为函数名
object = new Demo();
object.sayHello1();
object.sayHello2();
object.sayHello3();name = "Robben";
function Demo() {
var name = "Robben in local";
this.name = "Robben in object";
this.sayHello1 = function() {
console.info(name);
};
this.sayHello2 = function() {
console.info(this.name);
};
this.sayHello3 = function(){
return (function(){console.info(this.name);})();
};
//理解匿名函数的this指向的是window
var test = function() {
console.info(name);
console.info(this.name);
};
test();
}
// Method1
//Demo.prototype = Demo;
//Demo.prototype.constructor = Demo;
//Demo.name = "Robben in classlike object";
object = new Demo();
object.sayHello1();
object.sayHello2();
object.sayHello3();
// Method2
//object.sayHello2.call(Demo);