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

Js Pattern - Self Define Function的更多相关文章

  1. What is 'typeof define === 'function' && define['amd']' used for?

    What is 'typeof define === 'function' && define['amd']' used for? This code checks for the p ...

  2. [Node.js] 05 - Modules and Function

    一个 Node.js 文件就是一个模块,这个文件可能是JavaScript 代码.JSON 或者编译过的C/C++ 扩展. 模块是Node.js 应用程序的基本组成部分,文件和模块是一一对应的. No ...

  3. Spark笔记之使用UDF(User Define Function)

    一.UDF介绍 UDF(User Define Function),即用户自定义函数,Spark的官方文档中没有对UDF做过多介绍,猜想可能是认为比较简单吧. 几乎所有sql数据库的实现都为用户提供了 ...

  4. 【微信小程序】在js中导入第三方js或自己写的js,使用外部js中的function的两种方法 import和require的区别使用方法 【外加:使用第三方js导出的默认function的调用方法】

    如下 定义了一个外部js文件,其中有一个function import lunaCommon from '../lunaCommon.js'; var ctx = wx.getStorageSync( ...

  5. js in depth: arrow function & prototype & this & constructor

    js in depth: arrow function & prototype & this & constructor https://developer.mozilla.o ...

  6. js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit

    js in depth: Object & Function & prototype & proto & constructor & classes inher ...

  7. js in depth: closure function & curly function

    js in depth: closure function & curly function 闭包, 科里化 new js 构造函数 实例化, 不需要 new var num = new Ar ...

  8. 巧用JS内置对象Function

    在做练习的时候也好,做项目的时候也好,我经常会碰到想要的到一个字符串“”里面的东西的这样的需求. 注意,“”里面的东西可以是任何东西[],number等等 于是有了个大神教我一个绝招: 于是世界圆满了 ...

  9. js的Object和Function

    自己闲的没事干,自己想通过js的了解写一个Function和Object之间的关系,可以肯定的是我写错了,但是希望可以有所启发. Function和Object Function.__proto__ ...

随机推荐

  1. plsql developer 使用技巧

    plsql developer 使用技巧 Oracle数据库相信已成为很多企业构建自身关键业务的重要后台支撑,也是众多开发人员常常采用的后台.但Oracle自己提供的一套客户端工具不是很好用,极大的影 ...

  2. Java 单元测试(Junit)

    在有些时候,我们需要对我们自己编写的代码进行单元测试(好处是,减少后期维护的精力和费用),这是一些最基本的模块测试.当然,在进行单元测试的同时也必然得清楚我们测试的代码的内部逻辑实现,这样在测试的时候 ...

  3. IP网络5种基本寻址方式 (单播、多播、广播、任播、地域多播)

    Addressing methods The Internet Protocol and other network addressing systems recognize five main ad ...

  4. git中reset与revert的使用

    http://alpha-blog.wanglianghome.org/2010/07/30/git-partial-rollback/ reset(版本撤回) 格式 git reset [-q] [ ...

  5. java中判断是否为中文

    public boolean isChinese(String strName) { char[] ch = strName.toCharArray(); for (int i = 0; i < ...

  6. MyGeneration 数据库驱动为空

    重做系统后安装了MyGeneration  但是安装完成后发现驱动中没有驱动信息,查了下网上的解决方案发下下面的可以完美解决,特作备忘: The problem is because of multi ...

  7. 在eclipse.ini中指定jdk的方式

    在eclisep的安装目录,打开eclipse.ini文件,加上这么一行,如下红色所示,注意加在-Vmargs前面,这两种方式的区别是:第二种方式除了会有eclipse进程外还会启动个java进程. ...

  8. HDU5778 abs

    http://acm.hdu.edu.cn/showproblem.php?pid=5778 思路:只有平方质因子的数,也就是这题所说的   y的质因数分解式中每个质因数均恰好出现2次  满足条件的数 ...

  9. ubuntu使用问题与解决记录[持续更新]

    1. 添加到计划任务 为脚本增加可执行权限 sudo chmod +x yeelink.sh 将脚本加入cronjob(计划任务) sudo crontab -e 在cornjob文件中添加下面一行, ...

  10. ESXI安装

    1.设置从USB启动 按DEL进入BIOS设置 参考http://www.upanok.com/jiaocheng/68.html 先插入USB,在选择ADVANCAED BIOS FEATURES ...