var Keith = {
firstName: 'Chou',
describe: function() {
return this.firstName;
}
};
console.log(Keith.describe()); //'Chou'
var Keith = {
firstName: 'Chou',
describe: function() {
return this.firstName;
}
};
var Rascal={
firstName: 'King'
}
Rascal.describe=Keith.describe;
console.log(Rascal.describe()); //'King'
function f(){
return this.firstName;
}
var Keith = {
firstName: 'Chou',
describe:f
};
var Rascal={
firstName: 'King',
describe:f
}
console.log(Keith.describe()); //'Chou'
console.log(Rascal.describe()); //'King'
var name='keith';
function person(){
var name='rascal';
return this.name;
}
console.log(person()); //'keith'
var name='keith';
function person(){
name='rascal';
return this.name;
}
console.log(person()); //'rascal'
var Keith={
name:'keith',
describe:function(){
return this.name;
}
}
var name='rascal';
var f=Keith.describe;
console.log(f()) //'rascal'
function keith() {
return (this === window)
}
console.log(keith()) //true
function Keith() {
this.sex = 'boy';
}
var person = new Keith();
console.log(person.sex); //'boy'
var keith = {
sex: 'boy',
foo: function() {
return this.sex;
}
};
var rascal = {
sex: 'girl'
};
rascal.foo = keith.foo;
console.log(keith.foo()); //'boy'
console.log(rascal.foo()); //'girl'
var a = {
b: {
p: 'keith',
c: function() {
return this.p;
}
}
};
var person = a.b.c;
console.log(person()); //undefined
var person = a.b; console.log(person.c()); //'keith' console.log(a.b.c()); //'keith'
function keith() {
console.log(this);
return function() {
return this;
}
}
keith(); //window
keith()(); //window
var o = {
f1: function() {
console.log(this);
(function() {
console.log(this)
})();
}
};
o.f1(); //Object , Window
function keith() {
console.log(this);
}
var o = {
f1: function() {
console.log(this);
var f2 = keith();
}
};
o.f1(); //Object , Window
var o = {
f1: function() {
console.log(this);
var that = this;
(function() {
console.log(that);
})();
}
};
o.f1(); //Object , Object
var a = {
count: 0,
fun: function() {
'use strict';
return this.count++;
}
}
var f = a.fun;
console.log(f()) //'TypeError: this is undefined'
var keith = {
a: 'Hello',
b: ['b1', 'b2'],
c: function() {
this.b.forEach(function(item) {
console.log(this.a + ' ' + item);
})
}
};
keith.c();
//undefined b1
//undefined b2
var keith = {
a: 'Hello',
b: ['b1', 'b2'],
c: function() {
var that = this;
this.b.forEach(function(item) {
console.log(that.a + ' ' + item);
})
}
};
keith.c();
//Hello b1
//Hello b2
var keith = {
a: 'Hello',
b: ['b1', 'b2'],
c: function() {
this.b.forEach(function(item) {
console.log(this.a + ' ' + item);
}, this)
}
};
keith.c();
//Hello b1
//Hello b2
var o = {
f: function() {
console.log(this === o);
}
};
o.f(); // true;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有