Download & Extend

backport Function.prototype.bind for older browsers

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

Status:active» needs review

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.

AttachmentSizeStatusTest resultOperations
1025626-1-bind.patch1.71 KBIdleFAILED: [[SimpleTest]]: [MySQL] 29,619 pass(es), 213 fail(s), and 306 exception(es).View details | Re-test

#2

Status:needs review» needs work

The last submitted patch, 1025626-1-bind.patch, failed testing.

#3

Status:needs work» needs review

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....

AttachmentSizeStatusTest resultOperations
1025626-3-bind.patch982 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 35,958 pass(es).View details | Re-test

#4

Version:7.x-dev» 8.x-dev
Status:needs review» needs work

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

Status:needs work» closed (works as designed)
Issue tags:+ie8

Annd we don't need to care about it since D8 is IE9+ now :) tagging to IE8 module though.

nobody click here