Permalink
Browse files

Abstracting safe array copy function

  • Loading branch information...
1 parent ef139cb commit 0149597da84fe2fdb5f48b868c69e4ce09b3bbf3 @briancavalier committed Dec 7, 2011
Showing with 13 additions and 3 deletions.
  1. +13 −3 wire.js
View
16 wire.js
@@ -315,11 +315,11 @@ define(['require', 'when', 'wire/base'], function(require, when, basePlugin) {
factories.module = moduleFactory;
factories.create = instanceFactory;
factories.wire = wireFactory;
-
- listeners = parent.listeners ? [].concat(parent.listeners) : [];
+
+ listeners = delegateArray(parent.listeners);// ? [].concat(parent.listeners) : [];
// Proxies is an array, have to concat
- proxies = parent.proxies ? [].concat(parent.proxies) : [];
+ proxies = delegateArray(parent.proxies);// ? [].concat(parent.proxies) : [];
proxied = [];
modulesToLoad = [];
@@ -1026,6 +1026,16 @@ define(['require', 'when', 'wire/base'], function(require, when, basePlugin) {
return typeof it == 'function';
}
+ /**
+ * Creates a new {Array} with the same contents as array
+ * @param array {Array}
+ * @return {Array} a new {Array} with the same contents as array. If array is falsey,
+ * returns a new empty {Array}
+ */
+ function delegateArray(array) {
+ return array ? [].concat(array) : [];
+ }
+
// In case Object.create isn't available
function T() {
}

0 comments on commit 0149597

Please sign in to comment.