Questions tagged [javascript-inheritance]

25 questions
140
votes
12 answers

How to extend Function with ES6 classes?

ES6 allows to extend special objects. So it's possible to inherit from the function. Such object can be called as a function, but how can I implement the logic for such call? class Smth extends Function { constructor (x) { // What should be…
Qwertiy
  • 19,681
  • 15
  • 61
  • 128
16
votes
2 answers

Understanding the __extends function generated by typescript?

I am playing with Typescript and trying to understand the compiled Javascript code generated by the compiler Typescript code: class A { } class B extends A { } Generated Javascript code: var __extends = (this && this.__extends) || (function () { …
5
votes
1 answer

ES6 Class extending native type makes instanceof behave unexpectedly in some JavaScript engines?

Consider the following ES6 Classes: 'use strict'; class Dummy { } class ExtendDummy extends Dummy { constructor(...args) { super(...args) } } class ExtendString extends String { constructor(...args) { …
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
2
votes
3 answers

Object.create vs new

The following code works when I create my object with the constructor but when I do object.Create it doesn't get initialized properly. functionName is not a function. I have two questions. Why isn't the object.create working ? How would I organize…
1
vote
1 answer

how to manage super() constructor parameters in javascript

This is a short piece of code from mazeContainer.js with only necessary part- import Cell from "./cell.js"; import Player from "./player.js"; export default class Maze { .... setup(){ for (let rowNum = 0; rowNum < this.rows; rowNum++) { …
Sapinder Singh
  • 559
  • 6
  • 21
1
vote
1 answer

How to dynamically extend a class ref in javascript

I'd like to pass a class ref definition to a function. The function should then make the passed class ref extend another class. Heres an example. I would expect to see console.log output "Root constructor" but it does not because InputClass gets…
kevzettler
  • 4,783
  • 15
  • 58
  • 103
1
vote
1 answer