I am using a modular template in JavaScript. I wonder if we can prevent the redefinition of publicly available modules. For example, in the code below, function1, function2, function3 and function4 can be accessed from the outside, but I do not want to override. If these functions are overridden, I want the compiler to generate an error message
"use strict";
var $ = (function(){
return{
function1 : function(){
alert("this is Function1");
},
function2 : function(){
alert("this is Function2");
},
function3 : function(){
alert("this is Function3");
},
function4 : function(){
alert("this is Function4");
}
};
}());
$.function1();
$.function2();
$.function3=function(){
alert('function 3 is overridden');
};
$.function3();
source
share