Augmented implementation in JavaScript
来源:互联网 发布:远程数据库导入sql文件 编辑:程序博客网 时间:2024/04/27 14:06
For js, usually use augmented implementation for function as follows (self execute), the advantage are: if you function has a calculator function, and third party also has a calculator function, the calculator will include all the functions both from yours and third party. In the following code, the calculator will finally have 5 functions. When calculator is loaded for the first time, it will pass "{}" as argument because window.calculator is null, for the second time and then on, it will pass "window.calculator" as argument. If you want to let other places outside that function to use the variables or functions, you must return those variables or functions as object.
var calculator = (function (math) { math.add = function (a, b) { return a + b; }; math.subtract = function (a, b) { return a - b; }; math.multiply = function (a, b) { return a * b; }; math.divide = function (a, b) { return a / b; }; return math; })(window.calculator || {}); var calculator = (function (math) { math.doubled = function (a, b) { return (a + b) * 2; }; return math; })(window.calculator || {});
- Augmented implementation in JavaScript
- Round implementation in Javascript
- Implementation of Captcha in Javascript
- Mozilla Rhino: implementation of JavaScript in Java
- Multiple Implementation in C#
- md5 implementation in java
- OuterHTML implementation in Firefox
- XPath implementation in Clojure
- Stack Implementation in C++
- multiface implementation in ns2
- A SoundEx implementation in .NET
- Haar Wavelets Implementation in C#
- Implementation of exception in Linux
- CRC Implementation Code in C
- LRU cache implementation in C++
- Dynamic Array Implementation in Java
- A CRC8 Implementation In C#
- A CRC32 Implementation In C#
- Ubuntu_install_snmp_snmpd.sh
- 你害怕创新吗
- 251490958
- widget debug
- 创业:如何打造一个杀手级产品?
- Augmented implementation in JavaScript
- 创新服务的七要素
- 虚伪的奉承也有效
- LR脚本函数基础
- 蒂姆·库克的五项核心领导力
- 你为何没有成为领导者
- doubango耻辱榜
- JNA 的使用
- Some tips in Html