TL;DR If an object X has an object Y as its field instance, is there a way for Y to call upon or retrieve X without assigning X to also be a field instance of Y? I am writing a JavaScript program which implements Farkle, a die-based game. To run a game of Farkle, I instantiate one instance of the
Tag: es6-class
In JavaScript Class, super cannot access attributes, but can modify attributes?
The super attribute cannot be accessed, but can be modified? What does super stand for? Some people say it is prototype? I know that the function of Class is in the prototype of the object, but why can super.name =’Lucy’; modify the properties of the object instance? Answer Assigning to super.prop is useful when prop is defined on the parent’s
How can I make a method function inside a subclass inherit some properties
Trying to build a discord.js bot I ran into some mental gap. Let’s say I need my console application to be a puppy that does a trick and barks after that. So I would build a subclass for this in this fashion: But this wouldn’t make the application to bark. For that I assume the trick() function would need to
Webpack ES6 modules multiple class app organization
I’m building an app with webpack for the first time and i’m trying to wrap my head around organizing class files. I’m having trouble getting the code to work. I’m still new to ES6 and such, so my code below is probably very wrong but i’m not sure its my approach/concept or its my syntax. entry is index.js and I
javascript remove “onclick” event listener
I have tried many things, but none of them work. I wonder if it’s impossible? I know the ‘normal’ way with ‘bind’, but the arrow functions are much more readable and I prefer to use them. To better understand my question I made this sample code that illustrates the problem as fully as possible. Answer Because you didn’t add the
How to set a variable on prototype in ES6 Classes?
We know that in the code above, methods someMethod and someMoreMethod would get attached to the prototype of someInstance object. But, what if we want to attach some property (not method) to the prototype. I tried doing the following but it throws error: Answer ES6 classes do not currently support fields. However, you can add properties to the prototype directly:
Vuejs Es6 class reactivity
i’m trying to have a computed property in vuejs associated to a es6 class. My Vue instance looks like this: My class looks like this If i try to do something like that: but the setter is never called, like the reactivity has been lost and i don’t understand why. I also try: I pass customClass as a prop, but
Creating custom element without using class keyword
This is actually more a question about the object-orientation model in ES6. However I am going to use the creation of a new custom element as an example. So the new and shiny (as of today) method to create a new custom element is via customElements.define() which take in a tag name, a constructor, and options (which is optional) according
Serializing an ES6 class object as JSON
I’d like to serialize myClass object to json. One easy way I can think of is, since every member is actually javascript object (array, etc..) I guess I can maintain a variable to hold the member variables. this.prop.foo = this.foo and so on. I expected to find a toJSON/fromJSON library for class objects since I used them with other languages