-5
votes
1answer
57 views

Preventing a Javascript object function called twice [on hold]

I am trying to reuse an object but my function is getting called twice. Here is what I have: var KEYBOARD = { template: 'keyboard', getkeyboard: function(){ console.log(this.template); } } ...
2
votes
1answer
163 views

Is this JS code a good way for defining class with private methods?

I was recently browsing a open source JavaScript project. The project is a straight port from another project in C language. It mostly use static methods, packed together in classes. Most classes are ...
1
vote
0answers
75 views

JS closures - Passing a function to a child, how should the shared object be accessed

I have a design and am wondering what the appropriate way to access variables is. I'll demonstrate with this example since I can't seem to describe it better than the title. Term is an object ...
28
votes
8answers
5k views

Is splitting up a function into several inner functions an anti-pattern? [duplicate]

Imagine a long and complicated process, which is started by calling function foo(). There are several consecutive steps in this process, each of them depending on result of the previous step. The ...
0
votes
2answers
135 views

Is it a good idea for JS objects to draw themselves when the page loads?

So normally I would only use JS to modify the dom after the user interacts with something or some event goes off. This seems right for some reason. But I'm developing a widget based app where widgets ...
-1
votes
1answer
229 views

How to make C# methods work like javascript functions? [closed]

I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this - function makeVariable(terp) { var me = {value: 0}; return function () { ...
1
vote
2answers
473 views

What is the recommended approach for helper functions in JavaScript?

What is the recommended approach for helper functions? I would like to choose one technique, and run with it to create my new "class". Here are the design options I have pondered: Option 1: Helper ...
-1
votes
1answer
57 views

Concerning JavaScript prototype and the initial constructor function

I am going through a tutorial on OOP in JavaScript (javascriptissexy.com using OOP in JS: What you Need to know). The instructor is explaining the Constructor/Prototype pattern of object creation. I ...
2
votes
4answers
630 views

Call the database every time, or create an object in memory, and if so, how and how often to update?

I'm creating an app in javascript/nodejs and using neo4j as database. Let's say I have an entity User in my database. It has a bunch of properties, like boxes_collected and places_visited, which keep ...
0
votes
1answer
130 views

What's a similar functionality in JavaScript that insures the object has X data before any actions are taken?

If java/C#/etc one might do something like create a constructor with a parameter, the parameter being the thing the rest of the object may act upon. How is this done in JavaScript? I'm trying to ...
0
votes
0answers
90 views

When You Have Both Options, When Functional and When OOP? [duplicate]

Like (I suspect) a lot of JS devs, I tend to start with intuition first and then come to sound principles/practice with experience informing study of the comp. sci stuff I never really had any form ...
3
votes
1answer
646 views

Objects of different programming languages [closed]

Apparently, there are some resemblance between objects in JavaScript and dictionaries in Python. Each language defines an object a little different (and there is some logic that all definitions to be ...
3
votes
3answers
170 views

Which one subsumes the other: class-based object-orientation or prototypal inheritance?

In this talk: http://www.youtube.com/watch?v=hQVTIJBZook, Douglas Crockford claims that class-based object-orientation can be represented in terms of prototypal inheritance. The construction he gives ...
1
vote
2answers
256 views

Go with an object-oriented perspective [duplicate]

My OOP JavaScript question is at the very bottom if you want to skip my introduction. In an answer to the question Accessing variables from other functions without using global variables, there's a ...
3
votes
1answer
316 views

How come javascript, being a prototype based language, doesn't have an easy way to access the prototype?

May be this is a stupid question, but I'm kind of intrigued. Being JavaScript a prototype based language, with its pseudo-class function constructors sort of half baked (remember JavaScript: The Good ...
9
votes
3answers
3k views

Object Oriented Programming in JavaScript. Is there life without it? [duplicate]

At our company we have pretty large body of PrototypeJS based JavaScript code, which we are porting to jQuery for several reasons (not really important here). I'm trying to set up coding guidelines to ...
1
vote
1answer
813 views

JavaScript static methods retrieval

I have been thinking about it and wanted some feedback, recently I thought about doing it like this: function foo(){ if ( !foo.prototype.statics ){ foo.prototype.statics = { // ...
4
votes
2answers
361 views

Better OOP in Javascript - multiple methods or methods with options?

Let's say I have an object like this: function Foo() { this.parser = new DataParser(); }; Within Foo I have a method that does something like this: Foo.prototype.getResponse = function(message, ...
51
votes
2answers
4k views

Are there any OO-principles that are practically applicable for Javascript?

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by: Writing the functions to be used as classes by yourself Use a nifty class system ...
12
votes
4answers
5k views

Are UML class diagrams adequate to design javascript systems?

Given that UML is oriented towards a more classic approach to object orientation, is it still usable in a reliable way to design javascript systems? One specific problem that I can see is that class ...
0
votes
1answer
115 views

If I define a property to prototype appears in the constructor of object, why?

I took the example from this question modified a bit: What is the point of the prototype method? function employee(name,jobtitle,born) { this.name=name; this.jobtitle=jobtitle; this.born=born; ...
4
votes
1answer
1k views

How can we protect the namespace of an object in Javascript?

Continuing from my previous question: Javascript simple code to understand prototype-based OOP basics Let's say we run into console this two separate objects(even if they are called child and parent ...
8
votes
3answers
1k views

Javascript simple code to understand prototype-based OOP basics [on hold]

I know Javascript for some time, although I am not a heavy user, I know it the first from the time when Netscape was my browser. I pretty much understand the main things, but since JavaScript approach ...
3
votes
3answers
893 views

What's an Elegant and OOP way to create a tree from arrays and render it as a nested UL

I have a series of arrays which represent file system paths, so each next value is actually a directory deeper, for example: var a1 = ["Desktop", "Pictures", "Summer 2011"]; is the equivalent of ...
0
votes
3answers
1k views

Translating between Python-Django and Javascript

I have a conceptual question about 'translating' between objects I have stored in Django (in Postgres) that I want to use on the front-end. So I have a user object in Python that holds basic things: ...
2
votes
1answer
562 views

design of 'game engine' for small javascript games?

I'm making a group of two or three simple javascript games for fun. After someone finishes one game, they'll be presented with a harder or easier version of another game depending on whether the ...
4
votes
2answers
3k views

Best JavaScript Coding Structure Using Object Literal?

Object Literal has no doubt been established in recent years as one of the essential components to best JavaScript coding practices. However, I am not very sure about what is the best way to structure ...
2
votes
3answers
1k views

How to handle large scale js+jquery projects using well written, Object-Oriented JavaScript and jQuery code?

I love the whole user experience/interface thing and put a lot of jQuery and JavaScript (pure JavaScript for HTML5 stuff, like canvas, file API, etc). The problem I face now is that my codes are ...
2
votes
2answers
784 views

Javascript project for analysis and learning

I started learning and using Javascript now for about six months. First i started by following different tutorial on the internet. Testing them, playing with them and trying different variation. ...
5
votes
3answers
1k views

Why make JavaScript class based?

JavaScript is a prototype language. To turn it into a class based language adds little value? I am not talking about best-practice here. I remember reading an article from way back, which claimed that ...