Skip to content
Advertisement

Tag: oop

Constructor function vs Factory functions

Can someone clarify the difference between a constructor function and a factory function in Javascript. When to use one instead of the other? Answer The basic difference is that a constructor function is used with the new keyword (which causes JavaScript to automatically create a new object, set this within the function to that object, and return the object): A

In Javascript, what does this underscore mean?

I’m reading a tutorial on backbone.js here: http://addyosmani.com/blog/building-spas-jquerys-best-friends/ What are the underscores? (_index, _photos, _album) Why use them? Answer It means private fields or private methods. Methods that are only for internal use. They should not be invoked outside of the class. Private fields contain data for internal use. They should not be read or written into (directly) from outside

Does JavaScript have classes?

A friend and I had an argument last week. He stated there were no such things as classes in JavaScript. I said there was as you can say var object = new Object() He says “as there is no word class used. It’s not a class.” Who is right? Edit: July 2017 JavaScript classes introduced in ECMAScript 2015 are primarily

How to get a JavaScript object’s class?

I created a JavaScript object, but how I can determine the class of that object? I want something similar to Java’s .getClass() method. Answer There’s no exact counterpart to Java’s getClass() in JavaScript. Mostly that’s due to JavaScript being a prototype-based language, as opposed to Java being a class-based one. Depending on what you need getClass() for, there are several

Associative arrays in javascript

I have this object: Its used in this way: The problem is, in the addField() function the fields array is being set correct (perhaps because a numerical index is being used to refer to it) but the other 2 arrays (labels and rules) aren’t being touched at all. Doing a console.log shows them as empty in firebug. What do I

Is there a benefit to defining a class inside another class in Python?

What I’m talking about here are nested classes. Essentially, I have two classes that I’m modeling. A DownloadManager class and a DownloadThread class. The obvious OOP concept here is composition. However, composition doesn’t necessarily mean nesting, right? I have code that looks something like this: But now I’m wondering if there’s a situation where nesting would be better. Something like:

Advertisement