jquery - Javascript MDN Function prototype bind polyfill is enumerable in array -


i'm working on project in have created jquery plugin , various other js files use bind() in various places. client requested ie8 support out of blue, included function polyfills support ie8 in ie8 in loops following methods enumerable causes data corruption.

for (var d in this.originalresponse.timespans) {} 

in particular our issue regarding bind() , here mdn polyfill using

if (!function.prototype.bind) {   function.prototype.bind = function(othis) {     if (typeof !== 'function') {       // closest thing possible ecmascript 5       // internal iscallable function       throw new typeerror('function.prototype.bind - trying bound not callable');     }      var aargs   = array.prototype.slice.call(arguments, 1),         ftobind = this,         fnop    = function() {},         fbound  = function() {           return ftobind.apply(this instanceof fnop && othis                  ?                  : othis,                  aargs.concat(array.prototype.slice.call(arguments)));         };      fnop.prototype = this.prototype;     fbound.prototype = new fnop();      return fbound;   }; } 

the result of iteration give out iteration bind prototype unwanted. there way support bind method on ie8 without being enumerable?

update:

this.originalresponse.timespans structure object in key unix timestamp , value array of strings. when tried loop through getting iteration because polyfill (for reason unknown me) creating function prototype inside object enumerable.

update 2

the data being received ajax / json call, sample data structure server:

{      "timespans":[         {            "1417685819":[             ]       },       {            "1417772219":[             ]       },       {            "1417858619":[             ]       }    ],    "start":"7:00",    "current":"11:36",    "end":"23:00" } 

and after receiving these data sake of simplicity transform data structure this:

myclass.prototype.success = function( r ) {      var response = {         timespans:{}     };      response.start = r.start;     response.end = r.end;     response.current = r.current;      (var t in r.timespans)      {          (var tt in r.timespans[t])         {             response.timespans[tt] = r.timespans[t][tt];         }     }        var = this;     this.originalresponse = response;     // other code doing calculation based on this.originalresponse;    } 

if supporting old browsers doesn't support object.defineproperty, i'm afraid it's not possible.

if (!function.prototype.bind) {     object.defineproperty(function.prototype, 'bind', {         value: function() {             // function body here         }     }); } 

using object.defineproperty, default property/method not enumerable (won't show in enumeration), not configurable (can't deleted), , not writable (can't overwritten).

see doc on mdn more info.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -