Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created November 3, 2009 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/225353 to your computer and use it in GitHub Desktop.
Save hisasann/225353 to your computer and use it in GitHub Desktop.
var $ = {}; // jQuery? or prototype.js?
$.P = function () {
var $_ = arguments,
i = 1,
len = arguments.length,
args = [];
var toString = Object.prototype.toString;
if (toString.call(arguments[0]) !== "[object Function]")
throw "Please pass the first argument is the function";
for (; i<len; ++i) {
if (toString.call(arguments[i]) === "[object Function]") {
args.push(arguments[i].call($_));
continue;
}
args.push(arguments[i]);
}
$_[0].apply($_, args);
}
$.P(function(arg1, arg2, arg3, arg4) {
console.log(arg1);
console.log(arg2);
console.log(arg3);
console.log(arg4);
}, "hoge1", "hoge2", "hoge3", function() {
var foo = [];
for (var i=0; i<3; ++i) {
foo.push("foo" + i);
}
return foo.join(" ");
});
$.P("bar"); // error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment