跟谁学-高途课堂
约 231 字小于 1 分钟
2024-04-06
项目中的各种东西,熟悉项目,吹牛逼!
// 5.有用代码补充一下下面person和Person的原型链链关系并补充完整的原型链
function Person(name, age) {
this.name = name;
this.age = age;
}
const person = new Person('张三', 18);
person.__proto__ == Person.prototype
person.constructor == Person.prototype
Person.prototype.__proto__ == Function.prototype
Person.constructor == Function.prototype
Function.prototype.__proto__ == Object.prototype
Object.prototype.__proto__ == null
// 4. new的时候都发生了什么,手动实现new
// func为被new的类,构造函数
function new2(func) {
let obj = {}
obj.__proto__ = func.prototype
let res = func.call(obj, arguments)
return typeof res === 'object' ? res : obj
}
// 6.实现genrator函数的co执行器,类似async函数自动执行的效果,而不需手动调用next()
function* fn(a = 0) {
a = yield a;
let b = yield b;
let c = yield c;
return a+b+c
}
function co(fn, ...args) {
for (let key in fn()) {
return fn().next()
}
}
// 2.不用循环,创建一个1-100的数组,并且每个元素的值等于它的下标