-1
我想將多個對象合併到一個對象中,包括使用ES6語法的方法。我在這裏有一個小提琴:http://www.es6fiddle.net/isvfozdu/顯示我正在嘗試完成(下面的代碼)。如何將兩個對象合併到一個對象中,包括方法
我玩弄裝飾模式,看起來像他們應該工作,但最終沒有。
我試圖解決的問題是具有不同功能的單個對象,具體取決於其屬性,並且具有所有功能可能有害。
謝謝!
class A {
hi(){
console.log('hi');
}
}
class B {
bye(){
console.log('bye');
}
}
class C {
hello(){
console.log('hello');
}
}
// x = A & B, not C
x.hi();
x.bye();
x instanceof A // true
x instanceof B // true
x instanceof C // false
// y = A & C, not B
y.h1();
y.hello();
y instanceof A // true
y instanceof B // false
y instanceof C // true
這裏的想法是根據A
let a = new A();
if(a.isEnabled){
let b = new B();
magicFunctionOrSomething(a, b);
}
a.bye();
您需要在問題本身**中包含相關代碼**。 – Amit
已更改。謝謝阿米特 – Bradley
好。現在你能演示一下用例嗎? – Amit