I have something like
var foo = function(arg){
var something = {
myPropVal: "the code",
myMethodProp: function(bla) {
// do stuff with mypropval here
alert(this) // => DOMWindow
}
}
}
is this possible? can i access the contents of myPropVal from within myMethodProp given the
sure you can
var foo = function(arg){
var something = {
myPropVal: "the code",
myMethodProp: function(bla) {
// do stuff with mypropval here
alert(this) // => DOMWindow
alert(this.myPropVal);
}
}
alert(something.myMethodProp());
}
foo();
Yes, you can, below is an example.
obj = {
offset: 0,
IncreaseOffset: function (num) {
this.offset += num
},
/* Do not use the arrow function. Not working!
IncreaseOffset2: (num) => {
this.offset += num
}
*/
}
obj.IncreaseOffset(3)
console.log(obj.offset) // 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With