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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:13:43+00:00 2026-05-23T15:13:43+00:00

I have the following object: //the constructor function function NewsScroller() { } //now put

  • 0

I have the following object:

 //the constructor function
    function NewsScroller() {

    }


    //now put some config objects using the JSON structure
    NewsScroller.prototype.config = {
        serviceUrl : '/NewsProvider.svc/rest/GetNews/',
        pageIndex : 0,
        pageNumbers: 0
    }

//allows the sending of a page
NewsScroller.prototype.getNews = function (pageIndex) {

    //get all the newsItems
    var urlToGetJson = this.config.serviceUrl + pageIndex;


    $.getJSON(urlToGetJson, function (data) {


    alert(this.config.pageNumbers);


        $.each(data.NewsItems, function (i, item) {

            var item1DateSelector = '.scroller-pane #division-' + i + ' .date';
            $(item1DateSelector).html(formattedDate);

        });

    });


}

Which throws the error:

this.config is undefined [Break On
This Error]
alert(this.config.pageNumbers);

I can see from looking at the code I cannot access the prototype so I have 2 questions:

1) Why cant I access why is it out of scope? Surely a function in a function has access to the memebers contained within that function?
2) If I cant access it how do I set the object ‘pageNumbers’ in the ‘config’ object notation?

  • 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-23T15:13:43+00:00Added an answer on May 23, 2026 at 3:13 pm

    It’s out of scope because this loses context, since it’s jQuery’s ajax callback that is executing the function. Indeed other variables retain their lexical scope, so you can solve this with the self=this pattern, or try binding the function:

    NewsScroller.prototype.getNews = function (pageIndex) {
    
        //get all the newsItems
        var urlToGetJson = this.config.serviceUrl + pageIndex;
        function ajaxCallback(data) {
            alert(this.config.pageNumbers);
            $.each(data.NewsItems, function (i, item) {
                var item1DateSelector = '.scroller-pane #division-' + i + ' .date';
                $(item1DateSelector).html(formattedDate);
            });
        }
    
        $.getJSON(urlToGetJson, $.proxy(ajaxCallback, this));
    
    }
    

    Using the self=this pattern:

    NewsScroller.prototype.getNews = function (pageIndex) {
    
        //get all the newsItems
        var urlToGetJson = this.config.serviceUrl + pageIndex,
            self = this;
    
        $.getJSON(urlToGetJson, function(data) {
            alert(self.config.pageNumbers); // instead of this, we reference self
            $.each(data.NewsItems, function (i, item) {
                var item1DateSelector = '.scroller-pane #division-' + i + ' .date';
                $(item1DateSelector).html(formattedDate);
            });
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following object structure, deseralized from XML (WS): <ns2:Category> <ns2:CategoryId>800003</ns2:CategoryId> <ns2:CategoryName>Name1</ns2:CategoryName> <ns2:Categories> <ns2:Category>
I have the following JSON object: { response: { status: 200 }, messages: [
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have the following code #include <iostream> using namespace std; class Object { public:
I have the following definition of a boost::function object: typedef boost::function<std::string (std::string, std::string)> concat;
I have a the following java script object function eventTypeObj() { allEventTypes = [];
I use the following function to detect values that belonged to an object's constructor
I have an associative array (object) of the following construction var menu = new
We have the following object int [,] oGridCells; which is only used with a
I have the following File object pointing to a directory via symbolic link, File

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.