What does MooTools' Function.prototype.overloadSetter() do?

前端 未结 2 1580
南旧
南旧 2021-02-05 13:46

I\'m looking through the MooTools source to try and understand its .implement() and .extend() utilities.

The definition of each refers to a fun

2条回答
  •  广开言路
    2021-02-05 13:57

    The part that had me scratching my head for a while was the

    var enumerables = true; for (var i in {toString: 1}) enumerables = null;

    part, which turns out to be a test for the DontEnum bug that some browsers have. At first glance it seems like it should just set enumerables to null, but with the DontEnum bug toString is suppressed (wrongly, because the object's prototype.toString has the DontEnum flag) and enumerables is left as true.

    overloadSetter (or rather the resulting function) then has to check one at a time for the seven properties that the DontEnum bug affects, to see if they exist in the object argument.

提交回复
热议问题