News for hackers. Stuff that matters.
Re:Backbone has made me a better programmer by MatthewPhillips on Friday August 24, 2012 @09:16AM (#4427418)
Please don't learn anything from that code.
Re:Backbone has made me a better programmer by kevincennis on Friday August 24, 2012 @11:02AM (#4427885)
Aside from the always controversy-inducing lack of semicolons and the slightly unintuitive leading bang for the IIFE, I don't really see what's wrong with this code.
Re:Backbone has made me a better programmer by MatthewPhillips on Friday August 24, 2012 @11:18AM (#4427965)
Something doesn't have to be wrong to be bad learning material. That code is chock full of unconventional js. For example, why they declare their objects like this:

  var Typeahead = ...

  Typeahead.prototype = {

    constructor: Typeahead
    ...
rather than the usual

  function Typeahead() { ...
  
  Typeahead.prototype = { ...
  
is a mystery to me.
Re:Backbone has made me a better programmer by fourstar on Friday August 24, 2012 @12:46PM (#4428353)
I'm not sure why they are prefixing the initial plugin with a `!`, but if it's the same as using a `(` then would the reason they are using `var Typeahead = ...` is to keep that method scoped to just this plugin and not global as `function Typeahead` would be doing?

I'm kind of ignorant at the moment of proper best practices of js, but eager to learn more, so if you could explain to me why one is better than the other, that'd be rad :)

Re:Backbone has made me a better programmer by MatthewPhillips on Friday August 24, 2012 @01:34PM (#4428609)
No, the ! is to turn the function into an expression, and thus guarantee that it is executed. It is meant to protect against concatenating with JavaScript that is missing a semi-colon at the end of its file. This is extreme minutiae and why I said you shouldn't use that code to learn.
Re:Backbone has made me a better programmer by kevincennis on Friday August 24, 2012 @08:50PM (#4430610)
Yeah, fair enough. I have no idea what that's about.
Re:Backbone has made me a better programmer by politician on Friday August 24, 2012 @09:31AM (#4427468)
The code seems reasonable; could you explain why it's not?