Skip to content
Advertisement

Tag: oop

Isn’t polymorphism works wrong in JS ES

I’m currently working on a browser extension to manage opened tabs and I notice that in JS ES polymorphism works a bit strange when I declare class fields at the top of the class. Let say that we want to use polymorphism in object initialization. E.g. we have base class View: and derived class TabView: Now lets try to call

Making class instance reactive in Svelte using stores

I am learning Svelte by creating simple app. The logic is written using classes. The idea is, that all the data needed comes from class instance properties. Instances should not be instantiated more than once. I am using stores to provide components this instances. The problem is I can’t get reactivity using this approach. I tried readable and writable stores

What is the difference between class fields and properties in Javascript

I’m reading class fields proposal for JavaScript. I don’t understand why the authors call it ‘fields’ and not properties. MDN docs in class article speak about instance properties declared inside constructor and in next section about field declarations declared using new syntax. What is the difference between the two besides the syntax? Answer What is the difference between the two

Using `this` for Parent Function inside a Nested Function

In the Apple “classs”, how can the nested function countSeeds() retrieve the value this.price? jsfiddle: http://jsfiddle.net/VGqEa/ Output Answer put var self = this at the top of Apple, and then refer to this as self instead in the nested function. i.e.: You could also put the self=this statement at the beginning of this.cutOpen, since this will still refer to the

What is the best way to define dependent variables in an object?

In the Google developers recommendation for optimizing JavaScript code, they mention that the best way to declare/initialize new variables for object is to use the prototype. For instance, instead of: Use: However, in my case I have a dependency between variables, for instance: Using this.toWhom outside of the main constructor body or a method function of the object will yield

Advertisement