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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:38:39+00:00 2026-05-20T00:38:39+00:00

Is this valid Javascript syntax? What does it do? Parser.prototype = { // …

  • 0

Is this valid Javascript syntax? What does it do?

Parser.prototype = {

  // ...

  get currentState() {
    return this.state[this.state.length - 1];
  },

  // ...

}

See https://github.com/LearnBoost/stylus/blob/master/lib/parser.js.

Thank you!

  • 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-20T00:38:40+00:00Added an answer on May 20, 2026 at 12:38 am

    It defines a getter:

    Binds an object property to a function that will be called when that property is looked up.

    Read about Getters and Setters.

    This function is called when you access the property:

    var sth = obj.currentState
    

    Notice that it is not a function call (there are no ()), but a normal property access.

    A corresponding setter would look like this:

    set currentState(value) {
      // do something with value
      // value would be 42 in the next example
    }
    

    and would be called when you assign a value to that property, e.g.

    obj.currentState = 42;
    

    The get and set keywords a special operators to be used inside the object literal notation. You could also use __defineGetter__ and __defineSetter__:

    Parser.prototype.__defineGetter__('currentStatus', function() {
        return this.state[this.state.length - 1];
    });
    

    I’m not sure in which version it was introduced though, it might not be supported by all browsers (especially IE ;)).

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

Sidebar

Related Questions

I am new to javascript, but is this valid? <script type=text/javascript> if (condition()) {
Lately I saw working code-blocks like this: <script type=text/javascript src=//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> And according to RFC
I'm having some trouble getting JSON to store some Javascript as a string value.
What's the most complex/powerful code you can write that's valid in a maximum number
I seem to be getting conflicting advice in the books I read on this
PHP files can be used as external javascript files. Basically make a php file
I just read Ben Alman 's article on Immediately-Invoked Function Expressions and wondered about
I am new at JQuery and I have a specific question about the IF-THEN-ELSE
I am wondering my IE6 and IE7 is messing up dynamic HTML generated by

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.