2
votes
0answers
44 views

how many ways can you define a class in javascript and what are the advantages? [closed]

I like to use class based design in JavaScript and I come from a C++, C# background, but I have not standardized on any single method. Are there any advantages to any method, and does it have any ...
2
votes
1answer
52 views

Return value and keep members of javascript object?

I'm trying to work out someone else's code and I'm really stuck on how they've managed to do this. The code is very long so I'll try and give a simplistic example of what I'm trying to find out. I ...
1
vote
2answers
50 views

JS function prototype out of context node express

I have an issue using prototype in node with context. /** * Constructor. * * @param object opts The options for the api. * @param object config The application's configuration. ...
0
votes
0answers
42 views

What characteristics and best-practices in object-oriented JavaScript? [closed]

As an experienced JavaScript developer, but a relative-notice when it comes to using JavaScript in an object-oriented fashion, I'm struggling to wrap my head around what characteristics differentiate ...
2
votes
1answer
39 views

Multiple nested functions in javascript

I am kind of back engineering a javascript project and need to inject a function into some already writeen code. I want to be able to call something like the following function in javascript: ...
2
votes
4answers
94 views

Javascript Prototypes,objects,constructor??i am confused

I have gone through plenty of Stack Overflow question that had description but I seriously found them very confusing. What I want is a simple explanation,please don't refer a link. I'm totally ...
2
votes
1answer
61 views

OO programming in javascript: is it good practice to have attributes being objects themselves?

I've created some objects with Backbone the way I'm used to do in Java. var Lead = Backbone.Model.extend({ defaults: { lng: 0, lat: 0, distance: 0 }, initialize: ...
-1
votes
1answer
35 views

CoffeeScript: Error When Instantiating Object In Constructor [closed]

I'm getting a weird error when trying to instantiate an object inside of another object's constructor method. EDIT 3 For instance (with pictures): Here's the javascript Here's the compiled ...
0
votes
1answer
24 views

Reassigning prototypes of build-in types

Number.prototype= { constructor:Number min:10, max:15 }; var obj=new Number(); alert(obj.min); Here I have created a new prototype for the default Number constructor. Then a new ...
0
votes
0answers
19 views

How to solve: strict mode on the way towards implementation for real private prototype functions in javascript

The main purpose of this code is to provide private prototype functions (pretty much an answer to this dude's question) and create real private variables that are not visible and accessible from ...
2
votes
3answers
69 views

What is the difference between these prototype declaration?

Method 1: Rectangle.prototype.getArea = function() { return this.length * this.width; }; Method 2: Rectangle.prototype = { getArea: function() { return this.length * ...
2
votes
2answers
57 views

Problems with Backbone.js inheritance

I believed I had a good background in backbone.js but I have a problem I don't understand. Suppose we have these two views: BaseView = Backbone.View.extend({ foo: {}, initialize: ...
1
vote
5answers
67 views

How can I get the parent of an instance

in my project I need to get the instance of the object that created another instance of a second object. I bypassed the problem by sending the instance in the constructor of the second object, but ...
-1
votes
0answers
29 views

creating a singleton class from class inheritance

I'm developing a class (A) and I want to create a sub class (B) which would act as a singleton of its super class (A) thus i can use A = function(){ }; A.prototype.name; var B.prototype = A(); var ...
1
vote
2answers
39 views

jQuery OOP element parameters

I want to create a jquery slider using oop. This is the structure of my code : var photoGallery = new Slider(); function Slider(){ this.init(); } Slider.prototype = { el : { nav : ...
0
votes
0answers
54 views

Difference between defining an anonymous function and assigning it to an object property and defining a normal method?

Reading "The Secrets of a Javascript Ninja" by John Resig, I came across this snippet: var ninja = { chirp:function(){ return n>1 ? ninja.chirp(n - 1) + "-chirp" :chirp; } }; Does the ...
0
votes
2answers
47 views

Create a method from a string in JS

So I have a string "getNumber": I would like to use this string as a method for an object: myObj.getNumber() Is that possible? Thanks
1
vote
3answers
50 views

How can you call a variable in a method from within the object?

I'm trying to learn OOP in javascript. I made the following code that is supposed to return the time spent in a certain mailthread: function mailThread(url) { this.timerIsOn = true; this.c ...
0
votes
1answer
54 views

Why my extend() method in Javascript don't work for 3 and more objects?

I have 3 object. netBuilder Numbering NumberingMethodDefault And i have some extend method. extend: function (Child, Parent) { var F = function () {}; F.prototype = Parent.prototype; ...
2
votes
1answer
30 views

Jquery Plugin: Object not accessible from same instance

I'm making my first Jquery Plugin and overcome many problems after I found one that I can not find solution. The plugin convert a table in a tree-gridview doing a $(element).treeGD(); sentence, that ...
2
votes
4answers
87 views

OO JavaScript call parent method

I've been trying to get to grips with OO JavaScript and created a simple example. function BasePage(name) { this.init(name); } BasePage.prototype = { init: function(name) { this.name ...
3
votes
1answer
26 views

Defining Classes in JS (ES5 vs Prototype)

I am looking at some common ways of defining classes (Constructor Pattern in Book by Addy Osmani). 2 main ways I see: Simple Prototypes: function Person(name) { this.name = name; } ...
0
votes
1answer
31 views

Nested objects referring to each other?

Suppose I have something like this: network = { post: function(t) { console.log(t); } protocol: { init: function() { /* network.post("init") */ } } } The commented part, how would ...
0
votes
0answers
41 views

Html5 video plays only for some times

Before I go into the problem I would like to say that this is the first time I'm trying to write javascript using OOP. So please bear with me and guide me if I doing anything wrong. As title says I ...
2
votes
2answers
53 views

JavaScript - how to make it possible to inherit

I'm trying to make it possible to inherit from this class: function Vehicle(p) { this.brand = p.brand || ""; this.model = p.model || ""; this.wheels = p.wheels || 0; } ...
5
votes
2answers
73 views

Advantage of using method in OOP Javascript

I came across a JS file which was built in a strange manner: var modal = (function(){ var method = {}; // Center the modal in the viewport method.center = function () {}; // Open the modal ...
1
vote
0answers
33 views

Mimicing event inside callback function from external of callback

Upon a given event, I wish to trigger a given action. In particular, I would like to hide an editor by performing tinymce.editors['myID'].hide();. Turns out this method is only available within the ...
2
votes
1answer
33 views

Is this a valid way to assign properties to an object?

Is this a valid way to assign properties to an object? I have an if/ else statement and I want it to determine what the properties of p and i are. function game(){ var self = this; ...
113
votes
10answers
82k views

Constructors in JavaScript objects

Can JavaScript classes/objects have constructors? How are they created?
31
votes
7answers
3k views

What are the advantages that prototype based OO has over class based OO?

Why is class based OO so popular instead of prototype based OO? Do they teach the latter in schools? Though Javascript is prototype based, most people use it mostly functionally, or via frameworks ...

1 2 3 4 5 53
15 30 50 per page