I'm just trying to get a "getter" in javascript in this way
var Product = function(){
var self = this;
var _id = function() {
return self.styleCode + '-' + self.materialCode + '-' + self.colourCode;
}
self.materialCode = ''
self.colourCode = ''
..
self.id = _id()
}
..
var obj = new Product();
//.. initialize properies
obj.id // = "--"
But it seems doesn't call the function every time as I believed. I tried to use this Javascript: Use function as variable something like this
var Product = function(){
var self = this;
self.materialCode = ''
self.colourCode = ''
..
get self.id() { return self.materialCode + '-' + self.colourCode; }
}
but I get an exception on the get keyword. Any idea? Thanks
get self.id() { ... }--- what does this code mean?getis not cross-browser. This reserved word don't run in all browsers. I try to provide you another solution, I'm searching for it