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

  • Home
  • SEARCH
  • 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 9187877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:52:51+00:00 2026-06-17T19:52:51+00:00

I have been studying framework development for a few weeks, and I ran across

  • 0

I have been studying framework development for a few weeks, and I ran across what is highly suggested and pressured in the world of lib development, Immediately-invoking Anonymous Functions.

I never can get it to work, and I have failed to find a resource that explains in-detail the use and logic behind it.

Here’s what I know so far:

  • It’s immediately invoking – It runs everything anonymously, immediately.
  • It’s anonymous – It does not carry a name therefore the code inside of it is not “reachable” by exterior code.
  • You can pass global window, object and undefined parameters – That’s about all I know on that, but do not understand them completely.

I am looking not only for a detailed resource, but one that explains the logic behind it. Because I find it very illogical.

Here’s what I have:

(function( window, document, undefined ) {
    window.myThingy = myThingy;

    var myThingy = function() {
    };

    myThingy.prototype = {
        constructor: myThingy,
        create: function( elementToBeCreated ) {
            return document.createElement( elementToBeCreated );
        }
    };

})( window, document );

Then,

myThingy().create("div");

But it is still saying myThingy() [object] is not a function.

What am I doing wrong? Why should I use immediately-invoking functions and not just create a global myThingy = function() object? Why do I have to use window?

I know there are several resources on the net about this, but I can’t understand any of it. Some of them go half-way into detail, some of them try to go into detail, but fail to explain the critical stuff. Why is this so stressed when developing a framework?

Don’t worry, I’m not trying to “re-invent the wheel”, but I am trying, however, to actually learn JavaScript, not just the pre-packaged stuff.

A good answer should contain:

  • A good resource where it explains the logic behind immediately invoking anonymous functions
  • An insight to that link
  • What I am doing wrong with the code I provided
  • 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-17T19:52:53+00:00Added an answer on June 17, 2026 at 7:52 pm

    First off, you have not yet defined your function when you try to assign it to the global object so it is undefined:

    window.myThingy = myThingy;
    console.log(myThingy);//undefined
    

    You need to do the assignment after myThingy is defined:

    (function( window, document, undefined ) {
    
    
     var myThingy = function() {
     };
    
     myThingy.prototype = {
        constructor: myThingy,
        create: function( elementToBeCreated ) {
            return document.createElement( elementToBeCreated );
        }
     };
    
     window.myThingy = myThingy;
    
    })( window, document );
    

    Okay, next, you cannot use

    myThingy.create("div");
    

    because myThingy is a function and not an object. Function objects are created when the new keyword is issued to a function. You can make this change to convert your function into a function object:

    window.myThingy = new myThingy();//create a function object
    

    This pattern is not how all frameworks are implemented, but similar. Sometimes there is more abstraction. However, making these changes will allow your approach to work.

    Here is a demo of your code: http://jsfiddle.net/ZjRJW/


    Links

    Here are some of my favorites:

    http://ejohn.org/blog/simple-class-instantiation/

    http://ejohn.org/apps/learn/

    http://ejohn.org/blog/simple-javascript-inheritance/

    http://jibbering.com/faq/notes/closures/

    https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Details_of_the_Object_Model

    http://javascript.crockford.com/prototypal.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Over the last few weeks I have been studying the MVC design pattern for
I have been studying for my Software Development course and came across the question
I've recently been studying TDD, attended a conference and have dabbled in few tests
I have been studying (old) 3D rendering techniques for the past weeks and think
I've been studying Python 3 recently and I have come across a conundrum: I
i have been studying unity3d for a few months and i have done some
I have been studying Ruby for the past few days and I have noticed
I have been working with JQM for a couple of weeks and after studying
Hey peoples, I've been studying Java for a couple of weeks, and have decided
I have been studying Java for a few months and am now starting to

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.