Is in javascript possible to create php-like constructor?
I mean, in php you can do this
<?php
class myObj
{
public function __construct()
{
print "Hello world!";
}
}
//prints "Hello world!"
new myObj();
I have been playing with such an idea in JS. Is that even possible?
var myObj = function()
{
this.prototype.constructor = function()
{
console.log("Hello world!");
}
}
//I'd like to execute some actions without invoking further methods
//This should write "Hello world! into the console
new myObj();