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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:44:43+00:00 2026-06-08T22:44:43+00:00

I have an object, something like so var Egg = function(){ this.test = $(.slider

  • 0

I have an object, something like so

var Egg = function(){

   this.test = $(.slider .label);

    $('.slider').slider({
       min: 1,
       value: 2,
       step: 1,
       value: 10,
       slide: function(){
         this.test.html(ui.value)
       }
    });

}

I want to use my variable test inside the slider object. However in its current form this refers to the slider and not my egg object, and so trying to use this.test when the slider moves results in undefined.

How can I make this refer to my object and not the slider.

Thanks

  • 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-08T22:44:45+00:00Added an answer on June 8, 2026 at 10:44 pm

    this has dynamic scope, so inside the slide function this is referring to whatever object called that function. this is not equal to what it was equal to when the function is defined (i dont know if im saying that very clearly … read this http://hoolihan.net/blog-tim/2009/02/17/static-vs-dynamic-scope/). However, you can save this in another variable and access it that way

    var Egg = function(){
    
       var self = this;
    
       this.test = $(.slider .label);
    
        $('.slider').slider({
           min: 1,
           value: 2,
           step: 1,
           value: 10,
           slide: function(){
             self.test.html(ui.value)
           }
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript object that looks something like this: var myTextOptions = {
I have something like this: var Something = function(){ this.render = function(){}; $(window).resize(function(){ this.render();
I have a json object that looks something like this: Array ( [algorithm] =>
i have a javascript object declared something like: var myObject = {a:{b: c, d:
I have an object structure that looks like this: var Results = new List<ResultObj>()
I have an object which looks something like this class MyObject { string Name;
I have JSON object inside variable like this: var chessPieces = { p-w-1 :
I have a function that appends a div to another div. Something like: var
I have an object for like this: var obj = { c: { games:
I have something like : var myMenu= [ { 'My English Title':function(menuItem,menu) { ...

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.