Live data from Hacker News

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

webpop.github.com

21–30 of 38 posts

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

#21
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…

I'm not a JS programmer, but I'd say that always using the function expressions (var a = function() {}) is bad. I understand that it's more useful when you intend to manage it as an object, or as part of a bigger object (the additional reasons your first link gives).

But about the hoisting problems... For me, the real problem is that you're declaring a function inside a function. Or using variables with the same name. That's a bad practice, it doesn't make sense. It should be avoided instead of using language constructs to work around it.

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

#22
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…

Why would you want a function called "callback" polluting you global namespace?

What you suggest makes no sense in Javascript. Variable functions allow the developer to simulate namespacing in JS without polluting the global namespace.

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

#27

Earlier quoted context omitted.

This [0] is the only difference I am aware of. But I would love to hear someone talk about performance differences (if any). [0]: http://stackoverflow.com/a/336868/712889

I actually got in an argument with someone on SO the other day who swore blind that the only was to declare a 'class' was using this pattern. Took a fiddle to shut him up. I just don't get what it adds to your code apart from hiding simple function definitions in the visual trappings of a static helper object or closure. Javascript is already homogeneous enough without making it visually even more.

>> I just don't get what it adds to your code apart from hiding simple function definitions in the visual trappings of a static helper object or closure. Javascript is already homogeneous enough without making it visually even more.

What method do you use instead of the following, when creating namespaces?

var yourNamespace = {

    foo: function() {
    },

    bar: function() {
    }
};

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

#28

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…

This [0] is the only difference I am aware of. But I would love to hear someone talk about performance differences (if any). [0]: http://stackoverflow.com/a/336868/712889

The one I mentioned above, you cannot conditionally create functions using function declarations.

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

#29

Earlier quoted context omitted.

This [0] is the only difference I am aware of. But I would love to hear someone talk about performance differences (if any). [0]: http://stackoverflow.com/a/336868/712889

I actually got in an argument with someone on SO the other day who swore blind that the only was to declare a 'class' was using this pattern. Took a fiddle to shut him up. I just don't get what it adds to your code apart from hiding simple function definitions in the visual trappings of a static helper object or closure. Javascript is already homogeneous enough without making it visually even more.

Wait, I don't think that JavaScript is homogeneous, not in the least, for me it's really heterogeneous, I can look at 3 or 4 scripts developed by people of different skills and backgrounds and see it done in 3 or 4 completely different styles, visually and syntactically.

Did you messed up the wording over homogeneity?

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

#30
post #26

another similar plugin: https://github.com/bigspotteddog/ScrollToFixed

I am the author of ScrollToFixed, which has been out in the wild for a couple of years and does docking top, bottom, middle and still allows the fixed elements to move with the horizontal scroll, which is great for table headers.

I was thinking about posting it on HN when I got a break in the action. Haven't had a break in the action yet.

Post reply on HN