Consider the following simple object:
var foo = {
constructor: function(){
console.log("foo");
},
bar: function(){
console.log("bar");
}
}
//should return "foo\nbar"
foo.bar();
Is it possible to create a constructor for this variable object that would allow me to execute foo.bar() as well as foo.constructor() by just calling foo.bar()?
foo.bar()call that other function? You'd need to dothis.constructor()inside ofbarto achieve the desired result. It's unclear why you call this "a constructor", since it doesn't construct anything.