After moving from PHP to NodeJS (JavaScript) I am having some trouble with JavaScript's Anonymous Objects - I can't figure out how to create a constructor to an anonymous object like you would have in PHP with the __construct()
function or Python's __init__(self)
function. Maybe like Java [Link] JavaScript can't have anonymous constructors...
Solution:
After reading the comments and other answers, I came to find out that by using an anonymous function that returned an object you can gain this functionality:
var a = new function() {
var constTxt = [not constructed]';
/* emulating a constructor */
if (true) {
constTxt = '[constructed]';
}
return {
functionABC : function() {
return 'abc ' + constTxt;
},
functionDCF : function() {
return 'other function';
}
};
};