Why is this undefined:
var testObj = {
CONSTANT: "blah",
someVal: this.CONSTANT
}
console.debug(testObj.someVal); // prints "undefined"
If it has to do with the fact that I am actually creating a new prototype and therefore the this keyword is not working, then I'd also like to know the following:
I am using Dean Edward's base.js and I am trying to do something similar to the above: I have an object that extends Base:
Test = Base.extend({
testObj: {
someVal: this.CONSTANT
}
CONSTANT: "blah";
});
var test1 = new Test();
console.debug(test1.testObj); // someVal is undefined
In the above, if I do someVal: "blah" this it works as expected; I'm just not sure why I can't access this.CONSTANT. If its because this is applied to the scope of testObj and not Test, then how do I solve this (I tried setting a that: this variable, with no luck)?
Update: based on the answers I see that I am doing this wrong. My question now is: using the base.js model, is there a way to have "class-level" constants that are accessible from within the same class (outside of functions)?