Let's say that I am defining following class to be used in my AngularJs code:
app.factory("exampleClass", function () {
// constructor
function exampleClass(val) {
this.prop1 = val;
this.result = "";
}
// methods
exampleClass.prototype = {
doSomething: function (userVal) {
this.result = this.prop1 + userVal; // any way to avoid this?
console.log(this.result);
}
};
// return class
return (exampleClass);
});
// .. later in code
new exampleClass("another").doSomething("321");
console.log(scope.example.prop1);
Is there any way to evade referencing class fields (prop1 and result) with this. in doSomething method, while still being able to reference them from outside of class directly? Obviously I am trying to emulate something like public type fieldName in other modern languages - when this. is not present first look in instance variables?