I have defined a module using object literal notation as follows:
var myModule = {
myProperty: "someValue",
myConfig: {
useCaching: true,
language: "en"
},
saySomething: function () {
console.log( "XXX" );
},
functionA: function () {
// do something
),
functionB: function () {
// need call functionA
myModule.functionB(); // style 1
this.functionB(); // style 2
)
};
What's the purpose using keyword this, what's the difference between style 1 & 2.
I also noticed some people use var that = this
, and then that.func()
, how is this better? And where should I put the var that = this
, in my module.
What's the best practice for object literal notation?