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 6018879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:19+00:00 2026-05-23T03:20:19+00:00

I have found an API that’ll make working with CANVAS a lot easier. It

  • 0

I have found an API that’ll make working with CANVAS a lot easier. It allows selection and modification of individual elements on the canvas very easily. It’s EaselJS. The API doc is here. http://easeljs.com/docs/

I am Ok with the API so far. What confuses me is actually some javascript in there. The part that’s in bold or within * *(couldn’t get the formatting to work)
What kind of javascript structure is this?

(function(target){…content…})(bitmap)
and in the content, it references bitmap, which is something outside.

HERE IS THE CODE

   for(var i = 0; i < 100; i++){
    bitmap = new Bitmap(image);
    container.addChild(bitmap);
    bitmap.x = canvas.width * Math.random()|0;
    bitmap.y = canvas.height * Math.random()|0;
    bitmap.rotation = 360 * Math.random()|0;
    bitmap.regX = bitmap.image.width/2|0;
    bitmap.regY = bitmap.image.height/2|0;
    bitmap.scaleX = bitmap.scaleY = bitmap.scale = Math.random()*0.4+0.6;
    bitmap.mouseEnabled = true;
    bitmap.name = "bmp_"+i;

(function(target) {

*bitmap.onPress = function(evt) *

        {if (window.console && console.log) { console.log("press!"); }
        target.scaleX = target.scaleY = target.scale*1.2;
        container.addChild(target);
        // update the stage while we drag this target
        //Ticker provides a central heartbeat for stage to listen to
        //At each beat, stage.tick is called and the display list re-rendered
        Ticker.addListener(stage);
        var offset = {x:target.x-evt.stageX, y:target.y-evt.stageY};

        evt.onMouseMove = function(ev) {
            target.x = ev.stageX+offset.x;
            target.y = ev.stageY+offset.y;
            if (window.console && console.log) { console.log("move!"); }
        }
        evt.onMouseUp = function() {
            target.scaleX = target.scaleY = target.scale;
            // update the stage one last time to render the scale change, then stop updating:
            stage.update();
            Ticker.removeListener(stage);
            if (window.console && console.log) { console.log("up!"); }
        }

** }})(bitmap); **

    bitmap.onClick = function() { if (window.console && console.log) { console.log("click!"); } }
}
  • 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-05-23T03:20:19+00:00Added an answer on May 23, 2026 at 3:20 am
    (function(target){...content...})(bitmap) 
    

    is creating a lexical scope for content so that any var or function declarations in content do not leak into the global scope. Inside content, target is just another name for
    bitmap.

    You can think of this as similar to

    function init(target) { ...content... }
    

    and then an immediate call to it passing bitmap as the actual value of the target parameter
    but the first version interferes with the global scope even less — it doesn’t define init as a name in the global scope.

    EDIT:
    I think the purpose is not lexical scoping, but to make sure that the event handlers point to the right bitmap, instead of the last bitmap the for loop deals with.
    init(bitmap);

    See Event handlers inside a Javascript loop – need a closure? for more detail.

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

Sidebar

Related Questions

I have been working with the Ebay api for a project and have found
I have found some sample code on codeproject that allows for user impersonation. This
I have found that my HTML is, to be honest, very clunky. Small, simple
I have found some libraries or web services in PHP that does the job.
I have found that there is generally a singe type or namespace that takes
I have found an interesting issue in windows which allows me to cause the
I have created an API that is used on several sites. The client sites
Is there an API that allows you to define the maximum number of OpenAL
My team and I have found that documenting our project (a development platform w/
I have a small application that uses the same API as the powerscript examples

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.