Js Pattern - Self Define Function
This pattern is useful when your function has some initial preparatory work to do and
it needs to do it only once.In such cases, the selfdefining function can update its own implementation.
eg:
var selfFunc = function () { console.log("First Initialization!"); selfFunc = function () { console.log("-- Function Logic --"); }; }; window.onload = function () { selfFunc(); selfFunc(); selfFunc(); console.log("<br />"); };
Result:
First Initialization!
-- Function Logic --
-- Function Logic --
技术改变世界