Page MenuHomePhabricator

D835.id1494.diff
No OneTemporary

D835.id1494.diff

Index: src/core/__tests__/util.js
===================================================================
--- src/core/__tests__/util.js
+++ src/core/__tests__/util.js
@@ -2,6 +2,37 @@
* @requires javelin-util
*/
+describe('JX.$A', function() {
+ it('should return a new array', function() {
+ var a = [1, 2, 'c'];
+ expect(JX.$A(a)).not.toBe(a);
+ expect(JX.$A(a)).toEqual(a);
+ });
+
+ it('should return an array from a collection', function() {
+ var div = document.createElement('div');
+ var p = document.createElement('p');
+ var span = document.createElement('span');
+
+ div.appendChild(p);
+ div.appendChild(span);
+
+ expect(JX.$A(div.children)).not.toBe(div.children);
+ expect(JX.isArray(JX.$A(div.children))).toBe(true);
+ expect(JX.$A(div.children).length).toBe(2);
+ });
+
+ it('should return an array from an array-like object', function() {
+ var object = {'0': 1, '1': 2, '3': 'c', length: 3};
+ expect(JX.$A(object)).not.toBe(object);
+ expect(JX.$A(object)).not.toEqual(object);
+
+ expect(JX.$A(object).length).toBe(3);
+ expect(JX.isArray(object)).toBe(false); // just checkin'
+ expect(JX.isArray(JX.$A(object))).toBe(true);
+ });
+});
+
describe('JX.isArray', function() {
it('should correctly identify an array', function() {
Index: src/core/util.js
===================================================================
--- src/core/util.js
+++ src/core/util.js
@@ -30,15 +30,8 @@
*
* @group util
*/
-JX.$A = function(mysterious_arraylike_object) {
- // NOTE: This avoids the Array.slice() trick because some bizarre COM object
- // I dug up somewhere was freaking out when I tried to do it and it made me
- // very upset, so do not replace this with Array.slice() cleverness.
- var r = [];
- for (var ii = 0; ii < mysterious_arraylike_object.length; ii++) {
- r.push(mysterious_arraylike_object[ii]);
- }
- return r;
+JX.$A = function(object) {
+ return Array.prototype.slice.call(object);
};

File Metadata

Mime Type
text/plain
Expires
Oct 19 2025, 8:44 PM (11 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8838393
Default Alt Text
D835.id1494.diff (1 KB)

Event Timeline