if you call getData()
function without passing any parameter then value of the data variable in function is undefined.
So at this Line ternary operator is used.
data = (data === undefined) ? this.defaultData() : data;
So it will check whether data === undefined
condition which is true. therefore it will assign value of this.defaultData()
to the data attribute
In short when value of data
is undefined
that time following is the case
data = this.defaultData()
Otheriwse if data has a value means calling function getData("Hi")
with parameter then it will be evaluated as a
data = data // data = Hi
Now here var self = this;
is used to preserve the context of this
inside nested function which is mentioned below.
return (function parse(group) {
return self.change('groupTo', groupExp, group);
}(data));
Without self = this if i try to use this
in Nested function then it will point to the Global Object i.e window
Object in JS.
In following Code arg
is available inside the function as we are passing it in call of IIFE so it is availabel to pass in the call of doSomething function.
(function (local_arg) {
doSomething(local_arg);
})(arg);