Live data from Hacker News

Javascript the right way

jstherightway.com

11–20 of 43 posts

Re: Javascript the right way

#11
The way how Addy Osmani implements singleton pattern is rather disputable. I would implement singleton as a regular object that returns itself immediately if initialized for the second time.

His prototype pattern also doesn't look like the right way of doing things. Is there actually anyone that uses plain object descriptors? I would just create helper method that wraps Object.create() and takes prototype object as first argument and instance object as second argument. There is no need to use constructors in this pattern (either directly or inside helpers) unless you are targetting legacy browsers.

I also dislike the fact that public/local scope is emulated by misusing the return statement - this is ugly, confusing and it doesn't play nicely with other patterns such as prototype. If you need some notion of public/private scope then just use underscore notation.

Re: Javascript the right way

#12
Looks more like JS the java way. Singletons make no sense in a language that has global variables and never lets you stop an object from being duplicated. The command pattern makes no sense in a language with first-class functions. I'd steer clear of this resource if you want to write javascript the right way.

Re: Javascript the right way

#13

I really like the nav highlighting used on this (and http://phptherightway.com ). Specifically, I like that it highlights the nav element(s) for whichever sections are in view, rather than highlighting only one nav element at a time. Very elegant.

Check out Bootstrap's Scrollspy[1]. Its one implementation (of probably many) that I've seen of the nav highlighting that you mentioned.

[1] http://twitter.github.com/bootstrap/javascript.html#scrollsp...

Re: Javascript the right way

#14
post #12

Looks more like JS the java way. Singletons make no sense in a language that has global variables and never lets you stop an object from being duplicated. The command pattern makes no sense in a language with first-class functions. I'd steer clear of this resource if you want to write javascript the right way.

Obligatory:

http://norvig.com/design-patterns/

Re: Javascript the right way

#16
post #12

Looks more like JS the java way. Singletons make no sense in a language that has global variables and never lets you stop an object from being duplicated. The command pattern makes no sense in a language with first-class functions. I'd steer clear of this resource if you want to write javascript the right way.

Almost every javascript library you use is a singleton, so your second sentence makes no sense. Check the example, it is just the module pattern. If a programmer wants to deviate away from a pattern, the language lock-in won't stop them.

Also, the command pattern is a great tool for handling undo/redo on a UI. I think you are being way to dismissive of some good advice. Just because someone is trying to share a better way of doing things that is based on ideas created in another language does not detract from their value.

Re: Javascript the right way

#17
post #12

Looks more like JS the java way. Singletons make no sense in a language that has global variables and never lets you stop an object from being duplicated. The command pattern makes no sense in a language with first-class functions. I'd steer clear of this resource if you want to write javascript the right way.

I somewhat agree with your points.

You can't just explain every single design pattern available in any given language and then say, you now know how to write that language "The right way!".

Thats the feeling I got from this, it just goes into way too much detail about way too many things, and forgets to start with the basics, which is all you need to know to write JavaScript the right way.

How can you write any language the right way without knowing the basics?

This book could be an absolute disaster in the hands of people who don't know any better.

+1 for steering clear of this resource.

Re: Javascript the right way

#18
post #9

No mention of Crockford? :(

With all due respect, Crockford jumped the shark some time ago.

Douglas Crockford should be named in my opinion, he loves javascript! ...

Javascript: The Good Parts is a pretty good book, good real world examples, like one where Crockford shows you how to split a url with regular expressions in javascript

JSlint is a pretty good tool, great parsing, using C, going on in the source

JSON is great for data. Data is pretty important.

Re: Javascript the right way

#19
post #7

A very nice initial listing for applications, I'd love to see it completed! One framework I think is missing in the category "server-side" is derby.js ( http://derbyjs.com ), have you thought about adding it to the list?

I loves me some Derby (and Racer), but it's not ready for production use until it supports server-side authentication logic. (Supposedly it's on the way.)
Post reply on HN