abstract-object
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -234,3 +234,78 @@ /** `Object#toString` result shortcuts */ | ||
return result; | ||
}, | ||
/* | ||
@desc inject the function | ||
@param aOrgFunc the original function to be injected. | ||
@param aBeforeExec this is called before the execution of the aOrgFunc. | ||
you must return the arguments(new Arguments(arguments)) | ||
if you wanna modify the arguments value of the aOrgFunc. | ||
it will stop the execution of the aOrgFunc if you return | ||
a value not an Arguments object nor a undefined value | ||
@param aAtferExec this is called after the execution of the aOrgFunc. | ||
you must add a result argument at the last argument of the | ||
aAtferExec function if you wanna get the result value of the aOrgFunc. | ||
you must add a isDenied argument following the result argument if you | ||
wanna know whether the aOrgFunc is executed. | ||
you must return the result if you wanna modify the result value of the aOrgFunc . | ||
@Usage Obj.prototype.Method = inject(Obj.prototype.Method, aFunctionBeforeExec[, aFunctionAtferExec]); | ||
@version 1.1 | ||
@author Aimingoo&Riceball | ||
@history | ||
V1.0 -- first released. | ||
V1.1 -- | ||
Supports to denie the aOrgFunc execution in aBeforeExec. | ||
Supports around in the aAtferExec, the aAtferExec be always executed even though | ||
denie the aOrgFunc execution in aBeforeExec. | ||
+ isDenied argument to the aAtferExec function. notice the aAtferExec whether | ||
the aOrgFunc is executed | ||
eg: | ||
var doTest = function (a) {return a}; | ||
function beforeTest(a) { | ||
alert('before exec: a='+a); | ||
a += 3; | ||
return arguments; | ||
}; | ||
function afterTest(a, result, isDenied) { | ||
alert('after exec: a='+a+';result='+result+';isDenied='+isDenied); | ||
return result+5; | ||
}; | ||
doTest = inject(doTest, beforeTest, afterTest); | ||
alert (doTest(2)); | ||
the result should be 10. | ||
*/ | ||
inject: function ( aOrgFunc, aBeforeExec, aAtferExec ) { | ||
var arraySlice = Array.prototype.slice; | ||
return function() { | ||
var Result, isDenied=false, args=arraySlice.call(arguments); | ||
if (typeof(aBeforeExec) === 'function') { | ||
//the result | ||
// * a return value instead of original function. | ||
// * an arguments pass to original function. | ||
// * whether deny the original function. | ||
// * return the arguments to allow execution | ||
// * return undefined to allow execution | ||
Result = aBeforeExec.apply(this, args); | ||
if (util.isArguments(Result)) { | ||
args = arraySlice.call(Result) | ||
} | ||
else if (isDenied = Result !== undefined) | ||
args.push(Result) | ||
} | ||
!isDenied && args.push(aOrgFunc.apply(this, args)); //if (!isDenied) args.push(aOrgFunc.apply(this, args)); | ||
if (typeof(aAtferExec) === 'function') { | ||
Result = aAtferExec.apply(this, args.concat(isDenied)); | ||
} | ||
else | ||
Result = undefined; | ||
return (Result !== undefined ? Result : args.pop()); | ||
} | ||
} | ||
} |
{ | ||
"name": "abstract-object", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "AbstractObject with Object State Events Support, RefObject with RefCount and AddRef/Release Support.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/snowyu/abstract-object", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
55808
519
1
196