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. 背水一战 Windows 10 (4) - UI: 多窗口

    [源码下载] 背水一战 Windows 10 (4) - UI: 多窗口 作者:webabcd 介绍背水一战 Windows 10 之 UI 多窗口 示例1.自定义帮助类,用于简化 Secondary ...

  2. [教学] 将 Form 内的控件变成 Style 简易运用

    1. 在 Form 上放一个 TImage ,再一个 TText 到 Image 里面,并将 Image1.StyleName 设定为 BtnStyle,如下: 2.接着放一个 TButton,将 S ...

  3. 11.21 if条件语句 年月日执行判断

    <script language="javascript"> var nian=prompt("输入一个年份","") if(n ...

  4. dubbo管理控制台安装

    官网提供的下载路径好像不能用了,我也是在网上找的包,现在提供下载路径:http://pan.baidu.com/s/1nvPHQvZ 下载下来了,把他解压到wabapps->ROOT里面,先把t ...

  5. java之StringBuffer类详解

    StringBuffer 线程安全的可变字符序列. StringBuffer源码分析(JDK1.6): public final class StringBuffer extends Abstract ...

  6. loadrunner11中java vuser引用jar包

    1.创建工程,新建类,HelloWorld.java,代码如下: package com.liuke; public class HelloWorld { public String getHello ...

  7. 不简单的SQL查询和排序语句

    真不简单!! 一:使用select语句进行查询 语法: SELECT    <列名> FROM      <表名> [WHERE    <查询条件表达式>] [OR ...

  8. 为你的网页图标(Favicon)添加炫丽的动画和图片

    Favico.js 在让你的网页图标显示徽章,图像或视频.你设置可以轻松地在网页图标中使用动画,可以自定义类型的动画,背景颜色和文字颜色.它支持的动画,像幻灯片,渐变,弹出等等. 您可能感兴趣的相关文 ...

  9. io.js - 兼容 NPM 平台的 Node.js 新分支

    io.js(JavaScript I/O)是兼容 NPM 平台的 Node.js 新分支,由 Node.js 的核心开发者在 Node.js 的基础上,引入更多的 ES6 特性,它的目的是提供更快的和 ...

  10. ae

    根据属性提取要素(利用GP) http://blog.csdn.net/ewyetc/article/details/6746728