我想定義一個自動執行的匿名函數,但是它使用不同的參數運行幾次。是否可以執行兩次匿名函數?
(function(x){ console.log(x*x)})(2)
// output: 4
// I know this syntax is wrong, I am
// demonstrating how I would imagine it being implemented
(function(x){ console.log(x*x)})(2)(5)
// output is error, desired output: 4{Newline}25
這可能嗎?
編輯:基於@Charmander答案,似乎有可能 ,幾乎可以肯定是一個壞主意,但這個工程,我所期望的......
(function(x){ console.log(x*x); return arguments.callee})(2)(5)
簡答:沒有。我會做出更長的回答。 – Halcyon 2012-07-10 23:32:05
爲什麼它必須是匿名的?對功能進行引用是否是一個問題? – freakish 2012-07-10 23:32:48