-
Notifications
You must be signed in to change notification settings - Fork 0
FunctionObject
14paxton edited this page Jul 18, 2022
·
6 revisions
function extractFunctionBody(fn) {
var reg = /function \((.*)\)[ ]?{(.*)}$/g;
var match = reg.exec(fn.toString().replace(/\n/g, ";"));
if (match){
return match[2];
} else {
return "";
}
}
console.log("1", Function.prototype.toString.call(cloneNodeToDocument))
console.log("2",cloneNodeToDocument + '')
const entire = cloneNodeToDocument.toString()
console.log("3", entire.slice(entire.indexOf("{") + 1, entire.lastIndexOf("}")))
console.log("4", entire.replace(/^[^{]*{\s*/,'') )
console.log("5", entire.match(/^[^{]+\{(.*?)\}$/) )
console.log("6", entire.substring(entire.indexOf("{") + 1, entire.lastIndexOf("}")))
console.log("7", '(' + cloneNodeToDocument.toString() + ')()')
console.log("8", '(' + cloneNodeToDocument + ')()')
console.log("9",extractFunctionBody(cloneNodeToDocument))var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG_SPLIT = /,/;
var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function annotate(fn) {
var $inject,
fnText,
argDecl,
last;
if (!($inject = fn.$inject)) {
$inject = [];
if (fn.length) {
fnText = fn.toString().replace(STRIP_COMMENTS, '');
console.log("text", fnText)
argDecl = fnText.match(FN_ARGS);
console.log("args", argDecl)
argDecl[1].split(FN_ARG_SPLIT).forEach( function(arg){
arg.replace(FN_ARG, function(all, underscore, name){
$inject.push(name);
});
});
}
fn.$inject = $inject;
}
console.log(fn)
console.log(fn.toString())
return $inject;
}