inherit javascript
function Animal() { }
Animal.prototype.eat = function() {
return "nom nom nom";
};
function Bird() { }
// Inherit all methods from Animal
Bird.prototype = Object.create(Animal.prototype);
// Bird.eat() overrides Animal.eat()
Bird.prototype.eat = function() {
return "peck peck peck";
};function inherit(c, p) {
Object.defineProperty(c, 'prototype', {
value: Object.assign(c.prototype, p.prototype),
writable: true,
enumerable: false
});
Object.defineProperty(c.prototype, 'constructor', {
value: c,
writable: true,
enumerable: false
});
}
// Or if you want multiple inheritance
function _inherit(c, ...p) {
p.forEach(item => {
Object.defineProperty(c, 'prototype', {
value: Object.assign(c.prototype, item.prototype),
writable: true,
enumerable: false
});
})
Object.defineProperty(c.prototype, 'constructor', {
value: c,
writable: true,
enumerable: false
});
}
Also in JavaScript:
- conditional style react
- make alphabet js
- react get data attribute from element
- could not find a declaration file for module in react project
- generate unique id javascript
- http request javascript
- button inside popover not viible
- p5js add canvas in middle
- change style on click react
- how to code a minecraft json file mod
- nuxt js emit event
- javascript string array sort alphabetically
- recursion countdown javascript
- js indexof
- grepper add code answer
- add element to array javascript
- import dropdown react
- compare objects in javascript
- javascript get boolean if checkbox is checked
- using this to get name of the clicked element
- javascript variable shortcuts
- switch in react
- --resolveJsonModule
- variable in js