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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:30:08+00:00 2026-05-16T18:30:08+00:00

I’ll start with an example snippet: self.addwidget({ box: ns.box({ text: ‘Foobar’, fromTop: ~~(Math.random()*window.innerHeight), fromLeft:

  • 0

I’ll start with an example snippet:

self.addwidget({
    box:    ns.box({                        
                text:       'Foobar',
                fromTop:    ~~(Math.random()*window.innerHeight),
                fromLeft:   ~~(Math.random()*window.innerWidth),
                toTop:      240,
                toLeft:     40,
                css:        'foobar',
                easing:     'easeOutCirc',
                duration:   2000,
                events:     {
                    mousedown:      function(e){
                        e.target.position = {x: e.pageX, y: e.pageY};
                    },
                    mouseup:        function(e){
                        // "this" should reference be "box"                                     
                    }
                }
    }),
    delay:  3000
});

Short description:
ns.box() takes an object as argument and creates a new jQuery object. It uses jQuery.extend() to merge the events property object with the jQuery constructor $('<elem/>', {});
After that, ns.box() returns a new object which contains some methods.
—

What I want to archieve is to have access to those propertys / methods within the event handlers. Of course I cannot access box.somemethod at this point because I cannot reference the outer box property at this point. So I tried to change the scope from the event handlers with jQuery.proxy(), to this, but with no success.
this.somemethod is unreferenced even when proxied.
I also tried to proxy all objects top->down, no success either.

Is it even possible in a construct like this one, to access the propertys from the returned object of ns.box(), within the event handlers ?

  • 1 1 Answer
  • 1 View
  • 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-16T18:30:09+00:00Added an answer on May 16, 2026 at 6:30 pm

    You can achieve this with a scoping function, like this:

    self.addwidget((function() {
        var box = ns.box({                        
                    text:       'Foobar',
                    fromTop:    ~~(Math.random()*window.innerHeight),
                    fromLeft:   ~~(Math.random()*window.innerWidth),
                    toTop:      240,
                    toLeft:     40,
                    css:        'foobar',
                    easing:     'easeOutCirc',
                    duration:   2000,
                    events:     {
                        mousedown:      function(e){
                            e.target.position = {x: e.pageX, y: e.pageY};
                        },
                        mouseup:        function(e){
                            // You can access `box` here                         
                        }
                    }
        });
    
        return {
            box:   box,
            delay: 3000
        };
    })());
    

    By assigning the box to a var inside our scoping function, we create a symbol that the event handlers (which are closures) close over and thus have access to. We call the function immediately, having it return the object. References held by closures are enduring, and so…

    I use this pattern all the time because I don’t like having anonymous functions (your event handlers are anonymous, for instance); more here. If I were doing the above, I’d make those named instead, like this:

    self.addwidget((function() {
        var box = ns.box({                        
                    text:       'Foobar',
                    fromTop:    ~~(Math.random()*window.innerHeight),
                    fromLeft:   ~~(Math.random()*window.innerWidth),
                    toTop:      240,
                    toLeft:     40,
                    css:        'foobar',
                    easing:     'easeOutCirc',
                    duration:   2000,
                    events:     {
                        mousedown:      boxMousedown,
                        mouseup:        boxMouseup
                    }
        });
    
        function boxMousedown(e){
            e.target.position = {x: e.pageX, y: e.pageY};
        }
    
        function boxMouseup(e){
            // You can access `box` here                         
        }
    
        return {
            box:   box,
            delay: 3000
        };
    })());
    

    Those functions now have names that can show up in call stacks and error messages, but they’re completely private, not cluttering up the global namespace.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.