function Foo() {
getName = function () {
console.log(1);
};
return this;
}
Foo.getName = function () {
console.log(2);
};
Foo.prototype.getName = function () {
console.log(3);
};
var getName = function () {
console.log(4);
};
function getName() {
console.log(5);
}
Foo.getName();
getName();
Foo().getName();
getName();
new Foo.getName();
new Foo().getName();
new new Foo().getName();
let Fn = function (x = 0, y = 0) {
this.x = x;
this.y = y;
this.getX = function () {
console.log(this.x);
}
};
Fn.prototype.getX = function () {
console.log(this.x);
};
let f1 = new Fn;
Fn.prototype = {
getY: function () {
console.log(this.y);
}
};
let f2 = new Fn(1, 2);
console.log(f1.constructor===f2.constructor);
f1.getX();
f1.getY();
f1.__proto__.getX();
f1.__proto__.getY();
f2.getX();
f2.getY();
f2.__proto__.getX();
f2.__proto__.getY();
let n = 2,
fn = () => {
this.n *= 3;
n++;
return m=>console.log((++n)+m);
};
var f = fn(4);
f(5);
fn(4)(5);
f(6);
console.log(n);
let fn1=function(){
alert(1)
},
fn2=function(){alert(2)};
fn1.call(fn2);
fn1.call.call.call(fn2);
window.val = 1;
let json = {
val: 10,
dbl: function () {
console.log(this.val)
this.val *= 2;
}
};
json.dbl();
let dbl = json.dbl;
dbl();
json.dbl.call(window);
alert(window.val + json.val);