function People(name) { this.name = name } People.prototype.sayName = function() { console.log('My name is ' + this.name) } let p = new People('jirengu') p.name p.sayName()
当执行 new People 的时候发生了什么?
function People(name) { this.name = name } People.prototype.sayName = function() { console.log('My name is ' + this.name) } function new2(fn, ...args) { let o = Object.create(fn.prototype) fn.bind(o)(...args) return o } let p = new2(People, 'hunger') p.name p.sayName()
写一个函数,判断一个变量是不是基本类型
const isBasic = a => a===null || a === undefined || !a instanceof a.constructor