Linked Questions
138 questions linked to/from Javascript: Do I need to put this.var for every variable in an object?
2 votes
6 answers
134 views
Why does this code use <function>.call()?
Code is from mozilla website function Product(name, price) { this.name = name; this.price = price; if (price < 0) throw RangeError('Cannot create product "' + name + '" with a negative ...
0 votes
3 answers
442 views
How come an array inside an instanciated object returns undefined?
function test() { var test_array = []; } var arrayList = new Array(); arrayList[0] = new test(); arrayList[0].test_array[0] = "test"; (try it out) I'm trying to create an array, initialize an ...
1 vote
2 answers
1k views
Preferred way of encapsulating Javascript and defining private variables/methods?
So before I always used this method of encapsulating my Javascript: Classtype = (function (){ //private members var variable1; var variable2; // //public methods return { ...
1 vote
2 answers
618 views
Custom random number generator in JavaScript
I'm new to creating objects in JavaScript. I need to make a random number generator that doesn't repeat itself too often (I have not tried to implement that part in the code snippet below). How can I ...
1 vote
4 answers
614 views
Overriding setter on object
I have an Object with a getter and setter where I'm intending to protect a property so that it can only be updated through a method. Let's call this object Person which has the following structure: ...
2 votes
1 answer
549 views
Why are javascript functions within classes not hoisted?
class A { f1() { f2(); } f2() {} } var a = new A(); console.log(a.f1()); returns f2 is not defined. Whereas: { function f1() { return f2(); } function f2() { return 'f2'; ...
2 votes
1 answer
612 views
Changing class dynamic doesn't work properly
I am learning Vue.js and at the moment i am learning to interact with the css, i really would love to know why my code doesn't work, basicly i have a button, when i click that button, every 1 second (...
-1 votes
1 answer
992 views
OOP Javascript, Why this object doesn't work like expected?
What do I want to achieve? I have an class called Looper. I want to give each object a name and an own looper. Results I expect Created Looper Object... one Created Looper Object... two one - 1 two ...
2 votes
1 answer
957 views
In React, why do we call this in arrow function?
I have a question.. please let me know.. import React, { Component } from "react"; class App extends Component { constructor(props) { super(props); } handleClick = () => { ...
1 vote
2 answers
1k views
Uncaught TypeError: Object [object Object] has no method 'draw' game.js:202 draw
I have looked through many other answers of this question unable to find an answer. The issue seems to be that it isn't recognizing the World global in my game.js file. The html file is ordered ...
3 votes
3 answers
437 views
JS: OOP private functions / private fields [duplicate]
Systemname = { Question : { send: function() { console.log("send"); }, read: function() { console.log("read"); }, delete: function() { ...
0 votes
5 answers
343 views
Why these closure based private variables in JavaScript not working
I am experimenting imitating OOP like behavior in JS. I am trying to have (private) variables: id and name in function Person. To this function I am passing arguments which are used to initialize (...
2 votes
3 answers
228 views
Trying to create a JS class (with functions)
i'm trying to run my JS code in differend areas independently, so i wanted to create a class and found this article and my problem is, that I can't use functions, which are in my class in my class. ...
0 votes
3 answers
364 views
How to ensure durable-object's private members are truly private
Trying to learn how to create a durable object with JavaScript, but as you can see from the example below one can easily access any of the Person instance's members - What am I doing wrong? function ...
0 votes
1 answer
640 views
How can I prevent this class from instantiating?
I am using a jQuery plugin for creating classes. But I don't want my classes to be initialized unless I want them to. How can I prevent the following code from initializing, but be accessible if need ...