Ben Alman

benalman.com · Personal blog · on HN since 2009

Ben Alman, a JavaScript and jQuery developer, writes about JavaScript patterns, jQuery plugins and coding style.

What HN saysHN links it for his IIFE naming post, jQuery plugins such as postMessage and BBQ, a bookmarklet generator and his semicolon advice.
35HN people shared it
17linked it in comments
20stories submitted
128story points
1 year agolast shared
2009people per year2026

Most-shared posts

  1. 1
    Immediately-Invoked Function Expression (2010)
    8 people · 23 points · first shared 2010 · 16 comments on HN
  2. 2
    JQuery BBQ: Back Button & Query Library
    5 people · 57 points · first shared 2010 · 3 comments on HN
  3. 3
    There's no such thing as a "JSON Object"
    4 people · 7 points · first shared 2010 · 4 comments on HN
  4. 4
    A Bit of Advice for the JavaScript Semicolon Haters
    3 people · 5 points · first shared 2013 · 1 comments on HN
  5. 5
    Jquery run code bookmarklet
    3 people · first shared 2010
  6. 6
    Multiple var statements in JavaScript, not superfluous
    2 people · 9 points · first shared 2012 · discussion on HN
  7. 7
    JQuery Special Events
    2 people · 2 points · first shared 2010 · discussion on HN
  8. 8
    Partial application in javascript
    2 people · first shared 2015
  9. 9
    Star-wizzity-wipe in Webkit
    1 people · 12 points · first shared 2009 · 5 comments on HN
  10. 10
    JavaScript's Chuck Norris
    1 people · 7 points · first shared 2009 · discussion on HN
  11. 11
    Apparently, someone misses Makefiles
    1 people · 2 points · first shared 2013 · discussion on HN
  12. 12
    HN Bookmarklet to make all comments visible
    1 people · 2 points · first shared 2010 · 1 comments on HN
  13. 13
  14. 14
    JQuery Bookmarklet Generator
    1 people · 1 points · first shared 2010 · discussion on HN
  15. 15
    Jquery longurl plugin
    1 people · first shared 2011

What HN people wrote when they linked it

unjinxable · 2012-08-07
I found this great little jQuery bookmarklet generator from Ben Alman: http://benalman.com/code/test/jquery-run-code-bookmarklet/ You can just paste this code in and generate yourself a bookmarklet to reveal the quora answers (should work on all browsers). $('.blurred_answer_wrapper').removeClass('blurred_answer_wrapper'); $('.with_signup').removeClass('with_signup'); $('.signup_cta_on_answer').remove();
udp · 2011-05-29
It does work in FF4, but it's not widely supported enough to rely on just yet, you're right. I also find the best thing to do is use a hybrid approach (pushState where available, hashbang as a fallback.) If anyone else is interested in implementing this, there are some good frameworks[1][2] to give functionality similar to pushState via the fragment identifier. Note that these constantly poll the hash in browsers that don't support the onhashchange event. It's a good idea to turn down the polling frequency to half a second or so, because I've found it can cause performance problems in IE. [1] http://code.google.com/p/reallysimplehistory/ [2] http://benalman.com/projects/jquery-bbq-plugin/
pas · 2017-09-14
You can do it with IFRAME and postMessage communication. (Have the internal IFRAME send out resize data, and that's all you need to handle from the host page.) http://benalman.com/code/projects/jquery-postmessage/examples/iframe/
cabirum · 2015-06-17
Immediately Invoked Function Expressions (IIFE). http://benalman.com/news/2010/11/immediately-invoked-function-expressi… Not unique to js, e.g. upcoming php v7 will support these.
Nadya · 2015-06-17
Only evil people put their return value on a second line... Regardless: http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leader… Although to be fair: http://benalman.com/news/2013/01/advice-javascript-semicolon-haters/
icebraining · 2015-06-11
I believe you can use partial() from this post[1] to do something like this: var processT1 = (isOk, items) => items.filter(isOk).map(toOtherType).flatten(); var processT2 = partial(processT1, isOk); http://benalman.com/news/2012/09/partial-application-in-javascript/#pa…
rikkus · 2015-01-27
I've been looking for some real-world examples of how currying might be useful in javascript. Haven't not used a language which supports currying for any real world project, I'm interested to know how it can help. I found a page [1] which talks about currying in javascript, then says "Are there practical uses for currying in JavaScript? Not really." Can you point me at anything which will help me see why it's useful? [1] http://benalman.com/news/2012/09/partial-application-in-javascript/
nullobject · 2014-09-16
You're mostly right. The console var is assigned the result of an immediately-invoked anonymous function (http://benalman.com/news/2010/11/immediately-invoked-function-expressi… The result of this function is an object which contains the console functions (log, warn, error, etc). Moreover, these functions only exist inside the scope of the anonymous function, so the only way to access them is through the returned object. This prevents the global namespace from being polluted. So when you call console.log('hello'), you're applying one of those functions in the object returned by the anonymous function.
padolsey · 2013-11-09
I don't believe this is "the most practical explanation of closures out there" as the author claims, but it does present a use-case. The most important thing to grasp if you're fussed about naming concepts in JavaScript is the difference between a function, a scope [1], a closure [2], and an IIFE [3]. [1] https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functio… [2] http://unscriptable.com/2011/10/02/closures-for-dummies-or-why-iife-cl… [3] http://benalman.com/news/2010/11/immediately-invoked-function-expressi…
gingerlime · 2013-05-09
looks nice. What's the main differences between this and BBQ? http://benalman.com/projects/jquery-bbq-plugin/
eli · 2012-07-20
I thought binding to window.scroll was considered bad practice without something like this http://benalman.com/projects/jquery-throttle-debounce-plugin/
buddydvd · 2011-06-11
Instead of polling, you can define event handlers for <script>'s onload and onreadystatechange event to detect when jQuery gets loaded. See Ben Alman's jQuery bookmarklet generator for an example: http://benalman.com/code/test/jquery-run-code-bookmarklet/
ZoFreX · 2011-02-09
Yes, if I were forced to use JS for loading the primary content I would do that too. There are a couple of options for doing so if you don't want to roll your own (and you don't - it is actually a very complex thing to get working cross browser), JQuery History [1] which is nice and simple, and JQuery BBQ if you need a bit more control. Personally I think it's a little early for pushState, and degrading to #! is really ugly, so for now I would say just use normal page loads like everyone else unless you have a really good reason (good reason: GMail. bad reason: glorified blog.) [1] http://tkyk.github.com/jquery-history-plugin/ [2] http://benalman.com/projects/jquery-bbq-plugin/
niyazpk · 2010-05-24
I use this JQuery Bookmarklet Creator all the time: http://benalman.com/code/test/jquery-run-code-bookmarklet/
This one bit me the other day and forced me to switch JavaScript compressors because the one I was using (it was python-based) didn't get the IIFE (http://benalman.com/news/2010/11/immediately-invoked-function-expressi… right when appending files together. In this blog posting Jacob writes: The majority of lines however don’t end with semicolons because they simply aren’t necessary and I prefer the minimalist aesthetic. For me, \n character is enough and the semicolon character is redundant. He then points to the izs blog posting about it: http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leader… Jacob calls it more 'minimalist' however it does require you to know (and think about) the rules of when Javascript accepts a newline as a line terminator and when it doesn't. In terms of cognitive minimalism 'semis-everywhere' wins. @izs even acknowledges that part of the advantage is forcing the developer to learn: To the extent that there is an objectively “better” choice, it appears to me that the minimal-semicolon/comma-first style is slightly superior, both because it is fundamentally more scannable and because it encourages programmers to better understand the language they use. and later: If you don’t understand how statements in JavaScript are terminated, then you just don’t know JavaScript very well, and shouldn’t write JavaScript programs professionally without supervision, and you definitely should not tell anyone else how to write…
keyist · 2010-06-26
Imo, the most important technique (besides standard ajax with js lib of choice) is making use of hashchange and organizing your behavior into 'routes' based on the hash. You'll notice that Gmail does this -- it has URIs ending with #inbox, #label/action, etc. Using hash routes allows you to keep track of state and decouple event handlers that set state from code that updates the page. Plus you get back button functionality and bookmark support. Some background info on hashchange: http://blog.whatwg.org/this-week-in-html-5-episode-3 jquery library for dealing directly with hashchange: http://benalman.com/projects/jquery-bbq-plugin/ Higher-level jquery library for handling hashchange: http://code.quirkey.com/sammy/ . It has more assumptions and imposes more constraints on the structure of your code. But in return you get route parsing and a DSL. If you go through the examples/tutorials in those two libraries you should gain enough knowledge to get started.

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close