10
votes
4answers
156 views

JavaScript Good Patterns - Is this a good example?

I have been trying various formats of namespaces and modules patterns, however I have not come across a solution that I would use for all my projects. I've been developing the following, that would ...
8
votes
1answer
745 views

JavaScript Boilerplate - Review comments required

I am in between to create JavaScript Boilerplate (collection of best practices around) for low/medium complex project and will host on GitHub in sometime once finalized it. Have divided the ...
6
votes
1answer
993 views

Component-based system for JavaScript game

I'm creating a JavaScript/WebGL based game and would like you all to take a look at the current entity component system which I created for it. I've used it once before on another project, and while I ...
6
votes
0answers
57 views

Basic snake game

Coming from a Java background, this is my first JavaScript-only game. I'm looking for some advice on what to improve. Also, I'm having trouble when it comes to program design. Sometimes I don't ...
6
votes
3answers
292 views

Responsive module and tooltip module

Recently, I've noticed that my code looks so ugly because there were a bunch of functions and global variables. So, I started reading a little bit about design patterns. Now I come with something ...
5
votes
1answer
140 views

DRY + principle of least knowledge + MVC in JavaScript

Is there any way of improving this code? (Here's a JSFiddle with an example and comments) Example: A Hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a ...
5
votes
1answer
171 views

JavaScript Sandbox Pattern

Based on this Stack Overflow question I came up with the following code. I'd like your general thoughts about it. Code style, functional, logical, disadvantages, just anything you can come up based ...
4
votes
2answers
281 views

Issues with this pattern to restrict access to private members?

Since the original post, I have explored further regarding this pattern. In an effort to fix one self-percieved flaw (the lack of ability of prototype methods to access private object members), I have ...
4
votes
2answers
2k views

JavaScript event handlers, scope, and the module design pattern

I've been using JavaScript for some time now, but mostly just jQuery to prettify web pages. I've started doing some serious development with it in the last year. So, I want to make sure I'm not ...
4
votes
1answer
230 views

Notifications dropdown with TinyScroll

I'm relatively new to jQuery and am trying to learn best practices/design patterns with JavaScript. Came across this link and decided to try and put it to something useful. So far I've made a ...
4
votes
1answer
295 views

Possibly mixing prototype and module pattern

I have either created something beautiful or something monstrous, and I'm not really sure which, and I don't know where else to turn but here. What I've done: ...
4
votes
1answer
943 views

How are my javascript module pattern and promise pattern?

I'm working on an app that downloads some SVG paths from a server and draws them. Anything in here is open to critique, but specifically I'd like to review my use of a module pattern and my ...
4
votes
1answer
65 views

Structure a webapp using RequireJS

I've written a small webapp in JavaScript, and am now essentially rewriting it to use RequireJS. I'm doing this partly to get more familiar with RequireJS (which I have little experience with), as ...
3
votes
2answers
95 views

What is the proper way for one child object to access another child object?

To be proper and testable, I'm trying to stay away from global variables and coupling objects together. That being said, what is the best way for Object1 to interact with Object2 below? I have it ...
3
votes
2answers
127 views

Javascript velocity converter, fully chainable

I created this out of curiosity and it has some code duplication issues and the fact that sticking .yield() on the end of a call to a unit converter is pretty ...
3
votes
1answer
538 views

JavaScript Module Pattern with AJAX

I have an application which currently uses AJAX for CRUD operations on a simple Person object. The following script works fine, but I'm looking for some pointers ...
3
votes
1answer
282 views

Challenge: solution for this deep-iteration JavaScript function dilemma?

Trying to implement a deep-iteration function with some constraints, I've noticed the faster solution is iterating it twice! Any attempt to avoid this resulted in slower code. So, the challenge: can ...
3
votes
1answer
3k views

Pattern for creating a globally accessible custom plugin

I'm currently using this pattern to create and extend a globally accessible custom plugin to be used in a web application: ...
3
votes
2answers
28 views

DOM building using DocumentFragment

I want to build the markup below by iterating on an array of objects. The structure of the object is also listed below. I need some tips on how to make it clean. Markup I want to build: ...
3
votes
1answer
348 views

Improving PhoneGap/JavaScript application

I have a PhoneGap application that I wrote some time ago. After looking Doug Crockford's video seminar JavaScript: The Good Parts (http://www.youtube.com/watch?v=hQVTIJBZook) I was just wondering if ...
3
votes
2answers
1k views

How to add forms dynamically in javascript?

Example speaks for it self: ...
3
votes
1answer
86 views

Suggestions on view-specific (MVC) custom JS/jQuery structure

In my job I write a lot of small JS/jQuery "snippets" for changing the default behaviour in the base product according to what the customer wants. I tend to organize it so that I have one ...
3
votes
1answer
49 views

Is it a classical MVC (Xerox Parc) implementation?

I've been trying to understand the original MVC implementation (the Xerox Parc's one). I'm sure it has flaws, but it's a simple code to practice/learn the original MVC. Working example View ...
3
votes
1answer
297 views

First attempt at MVC JavaScript pattern

I would really appreciate a review of my interpretation of MVC here. It's as bare bones and clear as possible. I've based it on some in-depth reading but I don't know if I have understood everything ...
3
votes
1answer
210 views

Is there a way to simplify this pattern

I'm using the following pattern in my mobile app. The code snippet below manages stopwatch. Is there a way to simplify the code for better readability and probably getting away from needing to use ...
2
votes
3answers
491 views

What pattern do I use to refactor a lof of if/else statements

I have a set of if/else statements that trigger certain actions. As a first step, I was thinking about moving the logic in each if statement to be its own function, but any recommendations on what ...
2
votes
1answer
42 views

Filling two angular $scope variables with data

I'm unsure about how to simplify this method properly. The method is basically responsible to allocate data. The response object is a collection of objects. Each object contains an attribute called ...
2
votes
1answer
98 views

Javascript code pattern

I have been working on a javascript heavy project. There are sales, purchases, reports etc. What I've done is created a separate module for each i.e. a separate module for each i.e. a separate one for ...
2
votes
1answer
265 views

Creating boilerplate for jQuery plugins

I've been writing some smaller jQuery plugins lately, and I've been thinking of writing up some boilerplate that I can use when writing new ones. I have code that works (for now), but I want to share ...
2
votes
2answers
741 views

JavaScript MVC - review and suggestions

Before I start working on a quite JavaScript heavy application I would like you to review my JS MVC approach. How can it be improved? Are there any mistakes/issues I should be aware of? Since the ...
2
votes
1answer
65 views

Request for Review: genContent Plugin

WHAT: Plugin for inserting content WHY: Fallback for CSS generated content for IE Please review and suggest optimization tips and or improvement of code. See the TODO in code and offer advice. ...
2
votes
0answers
73 views

Decoupling with a self-descriptive mediator function

I don't have a lot of experience writing libraries and just recently started thinking a lot about structure and patterns. I wrote a tiny module manager based on the facade and mediator design ...
2
votes
0answers
44 views

Implement.js JavaScript module pattern

I have been playing with a new JavaScript module pattern to see what I can come up with. I think it's quite powerful and wanted to know if it is something people would find useful? I'm looking for ...
1
vote
3answers
215 views

1000+ of JSON objects in my case

I try to make a data of 1000 objects (incress in the feature) My JSON look like... ...
1
vote
3answers
375 views

Marionette.js Mediator ('global' commands vs app controller)

I am currently migrating a large backbone application over to Marionette and am curious as to the opinions on what is a better design for mediating activity between modules. I have an Application ...
1
vote
3answers
115 views

Improving Javascript code of a failed test

I just failed in a JavaScript test and I would really appreciate some comments of how I can improve so I can keep learning. The test was about making a form interactive, where the code should do ...
1
vote
1answer
227 views

Is this factory method a good approach?

We are beginning to learn Node.js and we are not always sure if we do it the right way. We have a strong object oriented background so the adoption is not always easy. Right now we implemented a ...
1
vote
2answers
139 views

Reduce JavaScript code. Double event, selector into one

Any idea how to write this code better."the html is nested tabs" Two selectors and two similar events, in a function would be better or a pattern to reduce lines. eg .jsbin ...
1
vote
1answer
1k views

More Revealing Module Patter in Javascript

It is known a Revealing Module Pattern in javascript, and here it is a little example. ...
1
vote
1answer
74 views

Am I using the JavaScript “module pattern” correctly?

I am reading this article about how you can organize JavaScript code for large projects. I am attempting to write a simple events calendar as a way to play with some of these design patterns. Using ...
1
vote
2answers
191 views

My take at OOP module/prototyping JavaScript

The last month I've been reading up on how to take my JavaScript code to the next level. I am a Java programmer at heart, so it feels nice when everything is encapsulated in classes/objects, and these ...
1
vote
0answers
32 views

Good practices with Angular Google Maps directives and JavaScript

Is this code good practice? What kind of design pattern should I use for this specific situation? The following function creates a new marker on a map. It sets a new image for it, except when the ...
1
vote
1answer
270 views

JavaScript Singletons and Module Pattern [closed]

Is there a preferred way of doing what I describe here. I want to namespace my JavaScript code and use the Singleton Pattern so that only one instance of my JavaScript app exists. I have seen two ...
0
votes
1answer
187 views
0
votes
1answer
45 views

Use of getters and setters with a car information example

I have very quickly mocked this up as an example model in Angular JS: ...
0
votes
1answer
32 views

Dynamic load of storage API wrapper [closed]

I'm facing app design problem. Basic on user choice i want to load one of the storage API wrappers, for example: Google Drive SkyDrive Dropbox They are wrappers providing same general methods ...
0
votes
1answer
2k views

How to re register dynamic scripts registered with ClientScriptManager in asp dot net using session was bad idea

Following the normal pattern of adding inline scripts to gridview row/s is a bad practice it used to work like below ...
0
votes
0answers
43 views

Compose in Javascript - Go ahead with this example?

I'm trying to use the good parts of Javascript and dont follow the classical inheritance. I studied and created this example of compose in Javascript, https://gist.github.com/fernandoperigolo/7789866. ...
-1
votes
1answer
61 views

Box(x,y,X,Y), box(x,X,y,Y), box(x,w,y,h), box(x,y,w,h) or box(fromPos,toPos)? [closed]

Say you are representing a box, or creating a function that slices a 2d array, or whatever. How do you represent it?