Skip to content

Commit

Permalink
Abstracting safe array copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Dec 7, 2011
1 parent ef139cb commit 0149597
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions wire.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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() {
}
Expand Down

0 comments on commit 0149597

Please sign in to comment.