Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:51:38+00:00 2026-06-14T05:51:38+00:00

I just read this article http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/ . In the section entitled #4 Adding Caching

  • 0

I just read this article http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/.

In the section entitled “#4 Adding Caching” it says:

By forming a closure around the mixins we can cache the results of the initial definition run and the performance implications are outstanding.

I don’t understand how this works– how does using the module pattern here lead to a faster/cached version of the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:51:40+00:00Added an answer on June 14, 2026 at 5:51 am

    basically, without using the closure, the mixin function will be created every
    time the mixin is used. By creating a closure, each of the function will be
    created once, and the mixin will reference those functions every time it is
    called. Since the mixin doesn’t have to recreate those functions every time it
    runs, its faster.

    without the closure

    var asRectangle = function() {
      // every time this function is called, these three functions are created
      // from scratch, slowing down execution time
      this.area = function() {
        return this.length * this.width;
      }
      this.grow = function() {
        this.length++, this.width++;
      }
      this.shrink = function() {
        this.length--, this.width--;
      }
    })();
    

    with the closure

    var asRectangle = (function() {
      // these functions are 'cached' in the closure
      function area() {
        return this.length * this.width;
      }
      function grow() {
        this.length++, this.width++;
      }
      function shrink() {
        this.length--, this.width--;
      }
    
      // this function is set to asRectangle.  it references the above functions
      // every time it is called without having to create new ones
      return function() {
        this.area = area;
        this.grow = grow;
        this.shrink = shrink;
        return this;
      };
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this article: http://weakreference.wordpress.com/2011/06/22/overriding-nslog-on-ios/ . The idea of the article is to add
I just read this article: http://www.acunetix.com/websitesecurity/upload-forms-threat.htm which discusses some of the security risks involved
I just read an article on the C++0x standard: http://www.softwarequalityconnection.com/2011/06/the-biggest-changes-in-c11-and-why-you-should-care/ It said nullptr was
I have read this article http://codebetter.com/iancooper/2011/10/06/avoid-testing-implementation-details-test-behaviours/ And I am confusing about Code developed in
I've just read about @Resource annotation from this article ( http://www.infoq.com/articles/spring-2.5-part-1 ) and wish
I just read this: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx I was under the impression that overwriting Object or
I just read http://aspalliance.com/2062_The_Darkness_Behind_DateTimeNow and started to wonder if this is really something to
I know all about this exception, read the msdn article here http://support.microsoft.com/kb/312629/EN-US/ but I
I just read this article and in the author's discussion of the Last-Modified HTTP
I read the following articles: http://searchcio-midmarket.techtarget.com/definition/just-in-time-compiler http://javarevisited.blogspot.in/2011/12/jre-jvm-jdk-jit-in-java-programming.html I am now really interested in knowing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.