Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Combine __dependencies property so that super methods have access

to the correct __imports
  • Loading branch information...
commit 7452d613b975af5ff2810e58c00577f1f0c73e38 1 parent d142cc1
Taka Kojima authored
Showing with 22 additions and 22 deletions.
  1. +22 −22 lib/minion.baseclass.js
View
44 lib/minion.baseclass.js
@@ -19,32 +19,30 @@
Otherwise, it is bad news bears doing something like this.nArray.push() in a Class method
because it modifies nArray on prototype, and thus any other instances of said Class
*/
- var _copy = function (obj) {
- var i, attr, c;
- // Null, undefined, number, boolean, string, function all get returned immediately, no need to copy them.
- if (!obj || typeof obj !== "object") {
- return obj;
- }
-
- if (obj instanceof Date) {
- return new Date().setTime(obj.getTime());
- }
+ var _copyTo = function (obj) {
+ while(arguments.length > 1) {
+ var prop, obj2, v = Array.prototype.splice.call(arguments, 1, 1)[0];
- if (obj instanceof Array) {
- return obj.concat();
- }
+ for (prop in obj2) {
+ v = obj2[prop];
+ if (v instanceof Date) {
+ return new Date().setTime(v.getTime());
+ }
- if (typeof obj === "object") {
- c = {};
- for (attr in obj) {
- if (obj.hasOwnProperty(attr)) {
- c[attr] = obj[attr];
+ if (typeof v === "object") {
+ if (v instanceof Array) {
+ obj[prop] = v.concat();
+ }
+ else {
+ obj[prop] = _copyTo({}, v);
+ }
+ }
+ else {
+ obj[prop] = v;
}
}
- return c;
}
- // If it fails, just return the original object.
return obj;
};
@@ -79,12 +77,14 @@
var _perInstanceProps = {};
var _this = this;
+ _proto['__dependencies'] = [].concat((this['__dependencies'] || []), (obj['__dependencies'] || []));
+
// Copy the object's properties onto the prototype
for(var name in obj) {
if(obj.hasOwnProperty(name)) {
- if(name !== "__static"){
+ if(name !== "__static" && name !== "__dependencies"){
// If we're overwriting an existing function that calls this.__super, do a little super magic.
if(typeof obj[name] === "function" && typeof _proto[name] === "function" && _doesCallSuper.test(obj[name])){
_proto[name] = _createSuperFunction(obj[name], _proto[name]);
@@ -121,7 +121,7 @@
for (var attr in _perInstanceProps) {
if (_perInstanceProps.hasOwnProperty(attr)) {
- this[attr] = _copy(_perInstanceProps[attr]);
+ this[attr] = _copyTo({}, _perInstanceProps[attr]);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.