Reputation: 7756
I have the bellow code,
(function(exports) {
"use strict";
var Common = function() {
this.loading = function(type){
this.type();
this.show = function(){
alert('show');
}
this.hide = function(){
alert('hide');
}
}
exports.Common = Common;
exports.Common = new Common();
}(window));
I was trying to access show()
and hide()
like ,
Common.loading('show');
Common.loading('hide');
But it throws an error,
TypeError: this.type is not a function
Upvotes: 0
Views: 46
Reputation: 68383
You are passing a string, it won't magically become a function when it reaches the method :)
You are trying to access a method which is property of this
, so replace
this.type();
by
this[type]();
Upvotes: 4