现有一段代码如下:
class Parent{
say(){
console.log('that method called from parent method');
}
}
class Son extends Parent{
sayChild(){
console.log('that method called from son method');
}
}
Son son = new Son();
son.say();
son.sayChild();
假设现在你不可以使用 extends 关键字来直接继承父类,只给你一个对象,你应该如何完成以下代码块:
class Parent{
say(){
console.log('that method called from parent method');
}
}
var sonObj = {
sayChild(){
console.log('that method called from son method');
}
}
function getSonClassByExtends(sonObj,Parent){
// finish the function code and make it work
}
var Son = getSonClassByExtends(sonObj,Parent);
Son son = new Son();
son.say();
son.sayChild();
各位前端大佬,这道题应该如何求解,谢谢!
