Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Function.prototype.bind is a feature of the newest JavaScript specification that, among other things, lets you write event handlers without inline closures. (The spec is on page 119 of the ECMAScript 5 standard for anyone who cares.) It's already available natively in Firefox 4 and coming soon to other browsers.
If we add a few lines to Drupal.js, we can make the same functionality available across browsers, which will let contrib write much cleaner JavaScript - and D8 core can clean up its act as well. Patch forthcoming.
Comment | File | Size | Author |
---|---|---|---|
#3 | 1025626-3-bind.patch | 982 bytes | ksenzee |
#1 | 1025626-1-bind.patch | 1.71 KB | ksenzee |
Comments
Comment #1
ksenzeeNote that the implementation in this patch is based on http://webreflection.blogspot.com/2010/02/functionprototypebind.html, which has an MIT-style license. I've written the author for permission to include it in Drupal as GPL code.
Comment #3
ksenzeeI didn't hear from the author of the implementation from #1, so here's an updated patch. It's loosely based on https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Fun....
Comment #4
nod_I'd like that too. There were talk of using underscore in core to help with functional kind of things.
Since it's for D8 now and that IE9+ supports it, we'd need this polyfill only for IE8 #1252178: Add Modernizr to core. Maybe see there if something is possible.
On a related note, I'd like to be able to use things like forEach classList where an IE8-only polyfill is needed, might be a good thing to extend the scope of this issue?
Comment #5
nod_Annd we don't need to care about it since D8 is IE9+ now :) tagging to IE8 module though.
Comment #6
jessebeach CreditAttribution: jessebeach commentedI've added an issue #2059811: Polyfill Function.prototype.bind.