var Foo = {
name: "Foo"
};
Foo.method = function () {
function test() {
console.log(this.toString());
}
test();
}
Foo.method();
Foo.method2 = function () {
var that = this;
function test() {
console.log(that);
}
test();
}
Foo.method2();
function Foo1111() {
name: "Foo1111"
}
Foo1111.prototype.method = function () {
console.log("this name in : "+ this.name);
};
function Bar() {
this.name ="Bar"
}
console.log("Bar.prototype.constructor is :" + Bar.prototype.constructor);
Bar.prototype = Foo1111.prototype;
console.log("Bar.prototype = Foo1111.prototype 以后,Bar.prototype.constructor is :" + Bar.prototype.constructor);
new Bar().method();
(new Bar()).method();
Function.prototype.add=function(name,fn){
this.prototype[name]=fn;
return this;
}
var Methods=function(){
this.addObj = function () { console.log("my is add to obj") }
};
Methods.add('a', function () { console.log("a") }).add('b', function () { console.log("b")})
console.log(Methods)
console.log(Methods.prototype)
var che=new Methods();
che.addObj()
che.a()
console.log(che.constructor)
console.log(che.constructor == Methods)
var a = 2
function foo(){
console.log(this.a)
}
var obj = {
a:1,
f:foo,
}
obj.f()
foo()
var a = 2
var obj = {
a:1,
f: ()=>{console.log(this.a) },
f1: function(){
(()=>{console.log(this.a)})() }
}
obj.f()
obj.f1()
var obj2 = {
a:1,
f: function foo(){
console.log(this.a)
},
}
var newObj2={
a:2
}
newObj2.f = obj2.f
obj2.f()
newObj2.f()
console