...

View Full Version : syntax question - dynamic property?



jbelis
05-29-2009, 05:59 PM
I came across this code and have a question about the line identified by // WHAT?

function Tokenizer(s) {
this.tokens = [];
this.tokenIndex = 0;
this.source = s;
}

Tokenizer.prototype = {
get token() { // WHAT?
return this.tokens[this.tokenIndex];
},

...

get: function() {
},

};

From the rest of the code, token is an object property of Tokenizer object instances. The goal of the above syntax appears to be for the value of the attribute to be set dynamically.

I have spend some time searching javascript references on the web but I have not come up with a page that describes this. Does anyone have a pointer?

Thanks!

Rihoj
05-30-2009, 03:54 AM
I beleive and I could very very easily be wrong, but I think there is supposed to be a period after the get in that line so it would look like get.token(). Because at the bottom of that code is get: function(), which to me says that there should be more to that part, and get.token() references that.

rnd me
05-31-2009, 07:32 AM
it's a getter function, though the syntax is deprecated.

alert(instance.token) would return this.tokens[this.tokenIndex];

search for "javascript getters" for more info...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum