Posted by ksenzee on January 13, 2011 at 3:30pm
3 followers
| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | javascript |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (works as designed) |
| Issue tags: | ie8, JavaScript clean-up |
Issue Summary
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.
Comments
#1
Note 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.
#2
The last submitted patch, 1025626-1-bind.patch, failed testing.
#3
I 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....
#4
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?
#5
Annd we don't need to care about it since D8 is IE9+ now :) tagging to IE8 module though.