Skip to main content
0 votes
0 answers
29 views

In JavaScript, Object inherits properties through the prototype chain. Example : // Parent Function function Person(name, age) { this.name = name; }; Person.prototype.hello = function() { console....
Rohìt Jíndal's user avatar
1 vote
1 answer
115 views

I have a number of classes all implementing the same interface. In order to create instances of these classes one should not use the constructor but rather a number of static methods which take a ...
Blue Nebula's user avatar
  • 1,222
0 votes
1 answer
67 views

I know there have been a lot of questions about module patterns, prototypical inheritance, ES6 classes, etc with excellent answers. This is not about discussing different patterns or the bad sides of ...
Aayla Secura's user avatar
2 votes
3 answers
588 views

I'm learning TypeScript about extending the interface. I unintentionally recognized that TypeScript allows extending interface from multiple classes. That made me surprised and I have researched a lot ...
LeoPkm2-1's user avatar
  • 199
0 votes
1 answer
74 views

I have standard handlers for the click, input and change events of my customized HtmlInputElement. I want to define these handlers like this: class MyInputElement extends HTMLInputElement { ...
htho's user avatar
  • 1,892
0 votes
1 answer
45 views

I have 2 "classes": const Person = function(firstName, birthYear){ this.firstName = firstName; this.birthYear = birthYear; } Person.prototype.sayHi = function(){ console.log('Hi!'); } ...
Vsevolod IV's user avatar
1 vote
2 answers
139 views

Is there a static equivalent of instanceof? I.E., rather than: obj1 instanceof Type something like: TypeA instanceof TypeB? I couldn't find anything on the matter, so I hacked together this: function ...
Werlious's user avatar
  • 593
0 votes
1 answer
48 views

function Animal(name) { this.name = name; } Animal.prototype.printName = function() { console.log(`my name is ${this.name}`) } function Dog(name) { Animal.call(this, name); this.speak =...
Sushmit Sagar's user avatar
0 votes
2 answers
115 views

So I tested this code: class C1 {} C1.prototype. f =function(){ return 1 } class C2 extends C1 {} C2.prototype. f =function(){ return super.f()+1 } And it throws a syntax error: 'super' keyword ...
user1533299's user avatar
0 votes
1 answer
75 views

The source object that printing the prototype chain can be various: [1, 2, 3] // array literal {a: 1} // object literal new Set() // built-in set new Promise( () =>{} ) // built-in Promise ...
Zhang Wei's user avatar
1 vote
1 answer
208 views

I'm trying to implement a class for a matrix with all the usual operations, just as an exercise. I implemented the common operations (+, -, ·) but my problem came when I tried to implement slicing ...
tac's user avatar
  • 153
1 vote
0 answers
122 views

I'm using a derived class from a base class using templates. I have something like: #include <iostream> using namespace std; template <typename T> class BaseClass { public: ...
tac's user avatar
  • 153
0 votes
0 answers
22 views

I have a simple piece of JavaScript code creating object b using Object.create and passing object a as the argument: const a = {}; const b = Object.create(a); console.log(b); It is my understanding ...
Nojan's user avatar
  • 913
2 votes
3 answers
85 views

I have a following code: const myFunc = () => { let var1, var2, var3; const setVar1 = (val) => { var1 = val } return { setVar1 } } Can you please tell me how this pattern is ...
JohnMalkovich's user avatar
0 votes
0 answers
56 views

This isn't so much a problem I'm having, rather than a general question about how classes/prototypes work in JS vs using closures. Lets say I have the following class (I'm going to omit the full body'...
hankthetank27's user avatar

15 30 50 per page
1
2 3 4 5
57