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. SSH实例(3)

    src文件夹的结构如下: clasDao文件: package com.school.service; import java.util.List; import com.school.dao.Cla ...

  2. 说说Java的内存

    首先,我们来看一段程序内存溢出的代码: import java.util.ArrayList; import java.util.List; public class TestMemoryLeak { ...

  3. [PHP] 使用Socket提供Http服务

    我的SimpleLoader里面的一块 https://github.com/taoshihan1991/simpleloader <?php namespace Server; class S ...

  4. Java --ClassLoader创建、加载class、卸载class

    一.java提供了三种ClassLoader对Class进行加载: 1.BootStrap ClassLoader:称为启动类加载器,是Java类加载层次中最顶层的类加载器,负责加载JDK中的核心类库 ...

  5. <记录学习>(前三天)京东页面各种注意点

    培训学校第1到3天先学习HTML现在流行的是HTML5,目前学习的是HTML5规范.(给有基础一定的人学习)前三天学习的是京东页面的编写,和以前写的不同,页面看上去和自己写的一样,但老师讲的还是有很多 ...

  6. Asp.net 实现Session分布式储存(Redis,Mongodb,Mysql等) sessionState Custom

    对于asp.net 程序员来说,Session的存储方式有InProc.StateServer.SQLServer和Custom,但是Custom确很少有人提及.但Custom确实最好用,目前最实用和 ...

  7. 如何在BPM中使用REST服务(1):通过程序访问网页内容

    这篇文章主要描述如何通过程序来访问网页内容,这是访问REST服务的基础. 在Java中,我们可以使用HttpUrlConnection类来实现,代码如下. package http.base; imp ...

  8. 命令行工具解析Crash文件,dSYM文件进行符号化

    备份   文/爱掏蜂窝的熊(简书作者)原文链接:http://www.jianshu.com/p/0b6f5148dab8著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 序 在日常开发 ...

  9. PS教程:20个新鲜出炉的 Photoshop 中级教程

    Photoshop 实例教程是提高 Photoshop 技能的最佳学习途径.今天,我向大家分享最新20个 Photoshop 进阶教程,提高你的图片处理技巧,制作时尚的效果.这些教程可以帮助把你的想法 ...

  10. Web前端开发工程师基本要求

    一位好的Web前端开发工程师在知识体系上既要有广度,又要有深度,所以很多大公司即使出高薪也很难招聘到理想的前端开发工程师.现在说的重点不在于讲解技术,而是更侧重于对技巧的讲解.技术非黑即白,只有对和错 ...