JSFiddle - React, Tailwind, and code Playground
by kodisha
JavaScript
var MyClass = function(){
//private
var PRIVATE_ID = 2331;
var _privateAdd = function(num1, num2){
alert(num1 + num2);
}
//public
return{
testPrivateParam:function(){
return PRIVATE_ID;
},
testPrivateMethod:function(){
//note there is no *this*
//so we write all private methods with _ prefix
_privateAdd(3,5);
}
}
}();
// Working
alert(MyClass.testPrivateParam());
//Working
alert(MyClass.testPrivateMethod());
//not workint - undefined
alert(MyClass.PRIVATE_ID);
//not working - Type Error
//alert(MyClass._privateAdd(3,2));