diff --git a/prime/parentize.js b/prime/parentize.js index 0d9dc28..e03c172 100644 --- a/prime/parentize.js +++ b/prime/parentize.js @@ -3,12 +3,31 @@ var prime = require("prime") var slice = require("mout/array/slice") +function attempt( fn, args, scope ){ + try{ + return [ null, fn.apply( scope, args ) ] + } catch( err ){ + return [ err, null ] + } +} + module.exports = prime({ parent: function(method){ - var parent = this._parent || this.constructor.parent - this._parent = parent.constructor.parent - var result = parent[method].apply(this, slice(arguments, 1)) - this._parent = parent - return result + var parent, result; + + parent = this._parent || this.constructor.parent; + this._parent = parent.constructor.parent; + result = attempt(parent[method], slice(arguments, 1) , this ); + this._parent = parent; + + if( result[0] ){ + throw result[0]; + } + + return result[1] } }) + + + +