function Programmer(name, company, expertise) {
if (!(this instanceof Programmer)) {
return new Programmer(name, company, expertise);
}
this.name = name;
this.company = company;
this.expertise = expertise;
this.writeCode = function () {
console.log("Writing some public static thing..")
}
}
柯里化
var curry = function (fn) {
var limit = fn.length;
return function judgeCurry(...args) {
return function (...args) {
if (args.length >= limit) {
return fn.apply(null, args);
} else {
return function (...args2) {
return judgeCurry.apply(null, args.concat(args2))
}
}
}
}
};
var currySingle = fn => judgeCurry = (...args) => args.length >= fn.length ? fn.apply(null, args) : (...args2) => judgeCurry.apply(null, args.concat(args2));
对象拷贝与赋值
var obj = {
name: 'xiaoming',
age: 23
};
var newObj = obj;
newObj.name = 'xiaohua';
console.log(obj.name);//xiaohua
console.log(newObj.name);//xiaohua
我们将obj对象赋值给了newObj对象,从而改变newObj的name属性,但是obj对象的name属性也被篡改,这是因为实际上newObj对象获得的只是一个内存地址,而不是真正的拷贝,所以obj对象被篡改。
var obj = {
name: 'xiaoming',
age: 23
};