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 --

 

 

转载于:https://www.cnblogs.com/davidgu/p/3332934.html

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页