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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:15:53+00:00 2026-06-15T17:15:53+00:00

This code gives me an error: $(function(){ var instance = new object(); literal.call(); });

  • 0

This code gives me an error:

$(function(){
    var instance = new object();
    literal.call();
});
var literal ={
    call : function(){
        instance.foo();
    }
}
function object(){
    this.selector = $('div');
    this.foo = function(){ this.selector.remove(); }
}

I want to make it run and I want to let the literal object out from $(function(){}). I don’t want to change the selector at a later time.

So I discarded this solution

$(function(){
    instance.selector = $('div');
    literal.call();
});
var instance = new object();
var literal ={
    call : function(){
        instance.foo();
    }
}
function object(){
    this.selector = $('div');
    this.foo = function(){ this.selector.remove(); }
}

And I discarded this also

$(function(){
var instance = new object();
var literal ={
    call : function(){
        instance.foo();
    }
}
literal.call();
});
function object(){
    this.selector = $('div');
    this.foo = function(){ this.selector.remove(); }
}

what is the best practice to do this?

  • 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-15T17:15:55+00:00Added an answer on June 15, 2026 at 5:15 pm

    Your problem is that the istance variable was local to the ready handler. As you don’t want to move your code in there (for whatever reasons), you will need to make the variable global:

    var istance;
    $(function(){
        istance = new object();
        literal.call();
    });
    var literal = {
        call: function() {
            istance.foo();
        }
    }
    function object(){
        this.selector = $('div');
        this.foo = function(){ this.selector.remove(); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: function foo(){ var x = 5; var y = 8.8; var exp1
This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
This code gives me an error: uses SDL uses SDLGraphics uses SDLImage screen: unowned
This piece of code gives a syntax error at the colon of elif process.loop(i,
I'm trying this code to access a property but it gives me an error:
I have this in my code: SelectList(blah, blah, blah, cu.Customer.CustomerID.ToString()) It gives a error
I am using backbone validate function but it gives this error again Uncaught TypeError:
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
I have this code, but when I run it it gives me: TypeError: Error
I don't understand why, but this code gives me a JavaScript error: <script type=text/javascript>

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.