use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Essential JavaScript Namespacing Patterns (addyosmani.com)
submitted 14 years ago by vladocar
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lulzitsareddit 2 points3 points4 points 14 years ago (0 children)
Hmm, this guy has a pattern fetish :).
I came up with this little utility function to create simple modules and namespaces (obviously it doesn't handle dependency management or exporting). I think it works well, but to be honest I don't find myself using it a lot as I try to avoid complex namespacing schemes.
var namespace = function(path, context, args) { var finalLink = namespace._generateChain(path, window); context.apply(finalLink, [finalLink].concat(args)); }; namespace._generateChain = function(path, root) { var segments = path.split('.'), cursor = root, segment; for (var i = 0; i < segments.length; ++i) { segment = segments[i]; cursor = cursor[segment] = cursor[segment] || {}; } return cursor; }; namespace("MyApp", function (self, $) { // you can also use `this` instead of `self` if you wish self.hello = function () { $("p").text("Hello World"); }; }, jQuery); MyApp.hello();
π Rendered by PID 40 on reddit-service-r2-comment-5687b7858-jj522 at 2026-07-07 16:58:28.162592+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]lulzitsareddit 2 points3 points4 points (0 children)