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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:20:35+00:00 2026-06-08T21:20:35+00:00

var a = { text : 3, logText : function () { console.log(this.text); },

  • 0
var a = {
    text : 3,
    logText : function () {
        console.log(this.text);
    },
    callLogText : function() {
        logText();
    }
};
a.callLogText();

This will genernate a ReferenceError: logText is not defined error message.

Instead, you prefix this to the logText() method, it will be ok. No error msg will pop.

var a = {
    text : 3,
    logText : function () {
        console.log(this.text);
    },
    callLogText : function() {
        this.logText();
    }
};

I really cant figure out the reason.

  • 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-08T21:20:36+00:00Added an answer on June 8, 2026 at 9:20 pm

    You need to learn the JavaScript scoping rules. This blog post gives a good introduction.

    In a nutshell, JavaScript follows some rules when you use a variable name (for the purpose of this explanations, function definitions are pretty much like variable declarations).

    What probably confuses you is this:

    var a = { b: ...};
    var a = function() { var b = ... }
    

    In both cases, you get a new variable a. In the first case, it’s an object with a property b. In the second case, it’s a function which has a nested scope in which a new variable b is defined.

    JavaScript will look in the current and all parent scopes for variables. But object definitions are no scopes. As far as JavaScript is concerned, the property b is invisible unless you make it visible by using the special variable this which always references the “current” object (in your example, that is a).

    Since the properties of the object a are not “in scope”, JavaScript can’t find logText() unless you tell it to look in this. If you don’t say anything, JavaScript will look in the current scope (the body of the function callLogText), then the parent scope (in which a is defined) and then in any parent scopes of that.

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

Sidebar

Related Questions

var func = function() { $(this).hide(); $parent = $(this).parent(); $parent.removeClass('my_signature_mouseover'); var text = $(this).val();
I am using replace method of string, var text = this ex is not
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new
This is my code: function text(var text) { var Value = document.getElementById(display).innerHTML; var New
Some folks helped me build a randomizer: function makeid() { var text = ;
I'm working with a web service that will give me values like: var text
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
If you use the regular expression /(this|a)/ Now if I have: var text =
this code works fine: procedure TForm2.Timer1Timer(Sender: TObject); var Text: string; begin SetLength (Text,555); GetWindowText

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.