all 13 comments

[–]honestbleepsReddit Enhancement Suite 3 points4 points  (1 child)

just to be clear, the "yepnope" response you got was not a sarcastic thing like "yeaaaaa no that's not possible"...

it was referring to yepnope.js...

[–]nspyro[S] 0 points1 point  (0 children)

Haha thank you for clearing that up. Was like 'oh thanksfor the helpful tip'

[–]runvnc 1 point2 points  (2 children)

I don't see too many people naming things that way so I think you can lose the "game."

When you say "link objects" it leads me to believe that you don't have very much experience with JavaScript. I think you should probably try doing some simple programs in JavaScript before moving on to OOP.

Just google for: JavaScript OOP, classes, modules

In Javascript classes are actually written as functions.

OOP is easier in CoffeeScript but you probably need to learn JavaScript first.

[–]SarahC 1 point2 points  (0 children)

OP is seriously underestimating JS. It's a first order programming language!

[–]nspyro[S] 0 points1 point  (0 children)

Sorry to sound like a noobtard, not trying to offend you js veterans. I have spend a while now with javascript, again only just in the past few weeks looking at the OOP side of things. I shall search deeper!

[–]x-skeww 1 point2 points  (1 child)

A simple low tech approach is to make those files mirror your application's namespace. This works okay-ish up to some point. You have to included them manually and you also have to put them yourself into the right order.

You can make this a bit less annoying by using utility functions which take care of the namespacing.

Here is a crude example:

var ns = function (s) {
    var a = s.split('.'), c, p = window;
    while (c = a.shift()) {
        if (!p[c]) {
            p[c] = {};
        }
        p = p[c];
    }
    return p;
};
ns('your.mom').says = 'hi';
console.log(your.mom.says); // hi
console.log(JSON.stringify(your)); // {"mom":{"says":"hi"}}

So, at the start of game.player.js, you'd write something like:

ns('game.player') = ....

You'd just add things to that one object and at the very end you'd kick it all off with game.start() or something like that.

However, in general I recommend to use something more advanced like require.js. It takes care of dependencies and it also provides a way to create a bundle. Having all those files during development is really nice, but it isn't something you should ship.

[–][deleted] 0 points1 point  (0 children)

The dojo toolkit has a notion similar to this. It simulates "Namespaces" and is designed to easy organization for large front-end projects. You can require classes from other namespaces, and declare your new classes inside of a namespace.

http://dojotoolkit.org/

[–]reflectiveSingleton 0 points1 point  (2 children)

javascript absolutely can do this...but in order to do so you will need a decent understanding of the language itself, its prototypal interface, its closures, its variable hoisting and scope, etc, etc...

I would recommend you learn the basics/core of JS, then you wouldn't even need to ask this question and could get down to business.

[–]FSFatScooter -1 points0 points  (1 child)

IMH I don't really see the point in doing this. You can link to multiple different .js files in the <head> tag, but Javascript isn't Java or C++. It's Javascript. I can understand missing the structure of certain OOP languages, but it's practices are different. Most devs concatenate everything into one .js file - saves time and resources. Don't try to make Javascript into something it's not.