一、
var name="abc";
var person={
name:'cba',
getName:function () {
return this.name;
}
}
console.log(person.getName());
var p1=person.getName;
console.log(p1());
var p2=new p1();
console.log(p2.name);
二、
var v='cba';
(function () {
var v='abc'
function A() {
var v='a'
this.getV=function () {
console.log(v);
}
}
function B() {
var v='b'
A.call(this);
}
var b=new B();
b.getV();
}())
三、
var i=1;
(
function () {
var s = new Date().getTime();
var si = setInterval(function () {
var n = new Date().getTime();
if(n <(s+100)){
i++;
}else{
console.log(i);
clearInterval(si);
}
},10)
}
)()
四、
var foo=1;
function main() {
console.log(foo);
var foo=2;
console.log(this.foo);
this.foo=3;
}
main();
new main()
五、
function one() {
this.name = 1;
function two() {
this.name = 2;
function three() {
var name = 3;
console.log(this.name);
}
return three;
}
return two;
}
one()()();
六、
这里写代码片