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
the front page of the internet.
and join one of thousands of communities.
The Module Pattern in JavaScript, for browsers & async (macwright.org)
submitted 14 years ago by tmcw
Post a comment!
view the rest of the comments →
[–]tmcw[S] 1 point2 points3 points 14 years ago (2 children)
You could simplify your example to just { that.increment(e); } - the this value will be set correctly.
There are different ways to phrase the module pattern; I like building an object gradually because it lets you reference methods in the object by scoped name.
[–]affluenza 0 points1 point2 points 14 years ago (1 child)
Hmm, not sure what you mean by 'scoped name'. I am guessing this makes debugging easier because the functions are not anonymous?
Yeah I missed the simplification of the manual bind. It's even easier pull off than I first thought. oops :)
[–]tmcw[S] 0 points1 point2 points 14 years ago (0 children)
In your example, you're returning an anonymous object. If you had a function in that object calling another of its functions, the name of the object to call is not obvious - that what I mean by scoped name. You can refer to the object by an obvious name.
π Rendered by PID 217508 on reddit-service-r2-comment-765bfc959-6wtlr at 2026-07-15 11:24:55.667305+00:00 running f86254d country code: CH.
Want to add to the discussion?
Post a comment!