Gets a length property containing the number of arguments the function expects:

function func(a, b, c) {}

console.log(func.length); //

var myFunc = function () {

    //  serialize the arguments object as a JSON string and use that string as a key in your cache object

    var cachekey = JSON.stringify(Array.prototype.slice.call(arguments)),

    if (!myFunc.cache[cachekey]) {

        var result = {};

        // ... expensive operation ...

        myFunc.cache[cachekey] = result;

    }

    return myFunc.cache[cachekey];

};

// cache storage

myFunc.cache = {};

References: 

JavaScript Patterns - by Stoyan Stefanov (O`Reilly)

JavaScript Patterns 4.8 Function Properties - A Memoization Pattern的更多相关文章

  1. JavaScript Patterns 5.3 Private Properties and Methods

    All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return ...

  2. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

  3. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  4. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  5. JavaScript Patterns 6.4 Prototypal Inheritance

    No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...

  6. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

    // the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...

  7. JavaScript Patterns 5.7 Object Constants

    Principle Make variables shouldn't be changed stand out using all caps. Add constants as static prop ...

  8. JavaScript Patterns 5.5 Sandbox Pattern

    Drawbacks of the namespacing pattern • Reliance on a single global variable to be the application’s ...

  9. JavaScript Patterns 5.4 Module Pattern

    MYAPP.namespace('MYAPP.utilities.array'); MYAPP.utilities.array = (function () { // dependencies var ...

随机推荐

  1. DataTable 除去列中重复值

    DataTable dtPCI = dtblSourceData.DefaultView.ToTable(true, new string[] { "Server Cell PCI" ...

  2. 背水一战 Windows 10 (9) - 资源: 资源限定符概述, 资源限定符示例

    [源码下载] 背水一战 Windows 10 (9) - 资源: 资源限定符概述, 资源限定符示例 作者:webabcd 介绍背水一战 Windows 10 之 资源 资源限定符概述 资源限定符示例 ...

  3. MyEclipse10启动Tomcat8出错

    问题一: java.lang.UnsupportedClassVersionError: org/apache/catalina/startup/Bootstrap : (Unsupported ma ...

  4. Mybatis批量添加对象List

    1.对应的xml文件: <!--批量添加--><insert id="insertStandardItemInfo" parameterType="ha ...

  5. python 学习笔记6(函数)

    函数 定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 1.减少代码重复 2.保持代码的一致性 3.方便修改,可扩展性 函数的创建 #简单 ...

  6. MD5加密操作

    MD5加密操作:MD5加密算法原理MD5的全称是Message-Digest Algorithm 5(信息-摘要算法),它的作用是让大容量信息在用数字签名软件签署私人密匙前被"压缩" ...

  7. WinForm 窗体应用程序(进阶)之一

    进程: 进程,简单的说,就是让你的程序启动另一个程序. 1.Process.Start("calc");//启动计算器 弊端:只认识系统自带的程序,如果写错系统会崩溃. 2. // ...

  8. css布局模式

    css布局模型在网页中,元素有三种布局模型: 流动模型(Flow) 浮动模型 (Float) 层模型(Layer) 流动Flow模型(一): 流动(Flow)是默认的网页布局模式.也就是说网页在默认状 ...

  9. 一行代码如何控制ipunt框里面值的长度

    <input  type="text"  id="你的id" maxlength="你想要的长度" onkeyup="thi ...

  10. JavaScript 事件绑定及深入

    一.传统事件绑定的问题 解决覆盖问题,我们可以这样去解决:window.onload = function () { //第一个要执行的事件,会被覆盖 alert(1);};if (typeof wi ...