开发者

Array.from implemented in jQuery

开发者 https://www.devze.com 2023-03-29 22:53 出处:网络
https://github.com/sstephenson/prototype/blob/1fb972开发者_运维技巧8/src/lang/array.js#L104 I need to separate Array.from() method from prototype js and implement it in jQuery. any idea where to star

https://github.com/sstephenson/prototype/blob/1fb972开发者_运维技巧8/src/lang/array.js#L104

I need to separate Array.from() method from prototype js and implement it in jQuery. any idea where to start?


$A is just a variable for this function:

function $A(iterable) {
  if (!iterable) return [];
  // Safari <2.0.4 crashes when accessing property of a node list with property accessor.
  // It nevertheless works fine with `in` operator, which is why we use it here
  if ('toArray' in Object(iterable)) return iterable.toArray();
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}
Array.from = $A;
...
Array.from("a,b,c,e,d") // outputs: ["a", ",", "d", ",", "f", ",", "e", ",", "e"]
0

精彩评论

暂无评论...
验证码 换一张
取 消