Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F18806630
D835.id1494.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D835.id1494.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D835: Use Array.prototype.slice in JX.$A
Attached
Detach File
Event Timeline
Log In to Comment