I have a class
function Man(){...}
Man.drinkBeer = function(){...}
I need to inherit SuperMan from Man. And I still want my Superman be able to drink some beer.
How can I do that?
I have a class
function Man(){...}
Man.drinkBeer = function(){...}
I need to inherit SuperMan from Man. And I still want my Superman be able to drink some beer.
How can I do that?
Object.setPrototypeOf(SuperMan, Man);
これにより、派生関数の内部__proto__プロパティが基本関数に設定されます。
したがって、派生関数は基本関数からすべてのプロパティを継承します。
これは、 ではなく、関数自体に影響することに注意してくださいprototype。
はい、紛らわしいです。
をサポートする既存のブラウザはありませんsetPrototypeOf()。代わりに、非標準の (しかし機能する) 代替手段を使用できます。
SuperMan.__proto__ = Man;