Open elclanrs opened 10 years ago
Great point. Can you provide some examples?
See my update above.
What about this:
var f = Over({
"string, number": function(s, n){ /* ... */ },
"string, string, number": function(s, s2, n){ /* ... */ },
"string, etc": function(s, etc){ /* ... */ }
});
(We could then support both versions)
Yeah, that's much better than my proposed solution, looks clean.
I got inspired by your script and gave it a try at building my own way following the solution you proposed. The script is very simple, it doesn't do any serialization or even throw exception, it just fallbacks to the closest signature or to an empty function. Extra arguments are always passed as an array at the end. I uploaded a little gist if you want to take a look. https://gist.github.com/elclanrs/6986187
:+1: for passing object to Over. This allows optional arguments be notes more human readable, instead of $_
.
var f = Over({
"string, object?, function": function(name, options, callback){ /* ... */ },
"string, [object], function": function(s, s2, n){ /* ... */ }
});
Nice script, I can see myself using this often but as-is it would break when minified, given that you're serializing the function. A workaround could be the approach that Angular takes, passing an array with the arguments as strings so they don't get mangled after minifying. Maybe something like this? Just thinking out loud: