Live data from Hacker News

Show HN: jQuery.pin – a plugin for making stuff stick

webpop.github.com

11–20 of 38 posts

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#11

Could do with some smoothing and polishing. Jerks all over the place. Also, what is with this new fashion of declaring functions as anonymous methods? var recalculateLimits = function () { /* snip */ }; var update = function () { recalculateLimits(); onScroll(); }; Have I missed a memo? EDIT: I forgot to say apart from my moaning, does the job, good code, good job! And it's only jerky when you use the scroll button o…

I learned this method with the book JavaScript the Good Parts, though it was a while ago and I can't remember the specific reasoning behind the books' recommendation.

From the other commenter's SO link, I found this link to go more in depth into the differences of declaring functions, and it seems to come down to having stricter control on the order of events with no surprises.

http://javascriptweblog.wordpress.com/2010/07/06/function-de...

And here's an example of one of the surprises you'll run into if you don't declare your functions in this way: http://www.adequatelygood.com/JavaScript-Scoping-and-Hoistin...

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#12

Could do with some smoothing and polishing. Jerks all over the place. Also, what is with this new fashion of declaring functions as anonymous methods? var recalculateLimits = function () { /* snip */ }; var update = function () { recalculateLimits(); onScroll(); }; Have I missed a memo? EDIT: I forgot to say apart from my moaning, does the job, good code, good job! And it's only jerky when you use the scroll button o…

From the discussion in one of the replies:

Named function expressions demystified http://kangax.github.com/nfe/

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#13
This is good but there are some more mature solutions out there, bootstrap has a very basic 'affix' plugin built in. However I have found the waypoints plugin to be absolutely amazing and flexible for any sort of sticky stuff:

http://imakewebthings.com/jquery-waypoints/

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#14
post #11

Could do with some smoothing and polishing. Jerks all over the place. Also, what is with this new fashion of declaring functions as anonymous methods? var recalculateLimits = function () { /* snip */ }; var update = function () { recalculateLimits(); onScroll(); }; Have I missed a memo? EDIT: I forgot to say apart from my moaning, does the job, good code, good job! And it's only jerky when you use the scroll button o…

I learned this method with the book JavaScript the Good Parts, though it was a while ago and I can't remember the specific reasoning behind the books' recommendation. From the other commenter's SO link, I found this link to go more in depth into the differences of declaring functions, and it seems to come down to having stricter control on the order of events with no surprises. http://javascriptweblog.wordpress.com/2…

That's definitely not in javascript the good parts. It's a new thing and its spreading like some sort of horrible virus. It has quite the opposite effect that you're prescribing to it.

Your second link describes both variable hoisting, a real problem which causes serious problems, and function hoisting that has never been a problem as almost every other modern language behaves that way.

You don't seem to be a polyglot or you'd understand the problem immediately. Variable hoisting is just downright bizarre if you've worked in almost any other language, whereas function declarations can be anywhere in most languages and so when they are declared is almost completely irrelevant to a programmer.

Artificially assigning them to a variable so that suddenly function declaration order does matter is just downright weird. The 'normal' function declaration is better and clearer.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#15
post #13

This is good but there are some more mature solutions out there, bootstrap has a very basic 'affix' plugin built in. However I have found the waypoints plugin to be absolutely amazing and flexible for any sort of sticky stuff: http://imakewebthings.com/jquery-waypoints/

Waypoints is more mature and can do much more complex stuff, but as with my earlier response about affix, for our use-case of pinning an unpinning the descriptions of the screenshots in our gallery, Waypoints didn't really come with anything out of the box.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#16

Could do with some smoothing and polishing. Jerks all over the place. Also, what is with this new fashion of declaring functions as anonymous methods? var recalculateLimits = function () { /* snip */ }; var update = function () { recalculateLimits(); onScroll(); }; Have I missed a memo? EDIT: I forgot to say apart from my moaning, does the job, good code, good job! And it's only jerky when you use the scroll button o…

From the discussion in one of the replies: Named function expressions demystified http://kangax.github.com/nfe/

That's actually discussing totally different concepts with a couple of side mentions (the only related bit being in Function names in debuggers).

But at no point do the use this technique for declaring functions any where else.

Interestingly in that article they don't even entertain the possibility that someone would ever declare a javascript function that way. A mere 3 years ago.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#17
post #11

Earlier quoted context omitted.

I learned this method with the book JavaScript the Good Parts, though it was a while ago and I can't remember the specific reasoning behind the books' recommendation. From the other commenter's SO link, I found this link to go more in depth into the differences of declaring functions, and it seems to come down to having stricter control on the order of events with no surprises. http://javascriptweblog.wordpress.com/2…

That's definitely not in javascript the good parts. It's a new thing and its spreading like some sort of horrible virus. It has quite the opposite effect that you're prescribing to it. Your second link describes both variable hoisting, a real problem which causes serious problems, and function hoisting that has never been a problem as almost every other modern language behaves that way. You don't seem to be a polyglo…

I'm probably not the best person to have a debate about this since I don't have a traditional CS background. I dabble in many different languages, but I'll never claim to be an expert in any.

To your point about this not being in the book JavaScript the Good Parts, I re-downloaded my purchase from Oreilly to double check, and throughout the book, all functions are declared as variables. Here's a screenshot from the second page of the "Functions" chapter, which is the first time a function declaration is introduced in the book: https://dl.dropbox.com/u/1517499/Screen%20Shot%202013-03-26%...

Edit: Just an edit to add that I quickly perused the pdf and couldn't pick out anywhere where he explained why he recommends this way. In any case, I'm always open to any arguments one way or the other.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#18
post #17

Earlier quoted context omitted.

That's definitely not in javascript the good parts. It's a new thing and its spreading like some sort of horrible virus. It has quite the opposite effect that you're prescribing to it. Your second link describes both variable hoisting, a real problem which causes serious problems, and function hoisting that has never been a problem as almost every other modern language behaves that way. You don't seem to be a polyglo…

I'm probably not the best person to have a debate about this since I don't have a traditional CS background. I dabble in many different languages, but I'll never claim to be an expert in any. To your point about this not being in the book JavaScript the Good Parts, I re-downloaded my purchase from Oreilly to double check, and throughout the book, all functions are declared as variables. Here's a screenshot from the s…

I don't think that's what he's addressing, though.

It's this:

var foo = function() { redeclaration(); }

that I believe he's referring to, unless I'm mistaken.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#19
For anyone wondering "why do we need jQuery plugins for simple things like this?", you may be interested in position: sticky. Here's an article: http://updates.html5rocks.com/2012/08/Stick-your-landings-po.... Worth noting that this hasn't actually been adopted as part of the spec, but it certainly would be a welcome addition in my opinion.

This plugin looks well-done, but I'm looking forward to a day when we don't need JavaScript to control layout like this.

Re: Show HN: jQuery.pin – a plugin for making stuff stick

#20
post #18
post #17

Earlier quoted context omitted.

I'm probably not the best person to have a debate about this since I don't have a traditional CS background. I dabble in many different languages, but I'll never claim to be an expert in any. To your point about this not being in the book JavaScript the Good Parts, I re-downloaded my purchase from Oreilly to double check, and throughout the book, all functions are declared as variables. Here's a screenshot from the s…

I don't think that's what he's addressing, though. It's this: var foo = function() { redeclaration(); } that I believe he's referring to, unless I'm mistaken.

I don't believe so. It sounds like he prefers using function declations to function expressions. And this is incorrect according to most js gurus. For example:

http://javascriptweblog.wordpress.com/2010/07/06/function-de...

From that link:

"b) Function Expressions are more versatile. A Function Declaration can only exist as a “statement” in isolation. All it can do is create an object variable parented by its current scope. In contrast a Function Expression (by definition) is part of a larger construct. If you want to create an anonymous function or assign a function to a prototype or as a property of some other object you need a Function Expression. Whenever you create a new function using a high order application such as curry or compose you are using a Function Expression. Function Expressions and Functional Programming are inseparable."

Also this link: http://kangax.github.com/nfe/

brings up these disadvantages to function declarations:

* can't conditionally declare functions with consistent results across browsers * function declarations cannot appear in blocks (technically), though many implementations allow this in practice

finally, i'd argue that function expressions encourage you to think of functions as the first class objects js intended them to be

Post reply on HN