Calling a public function without creating a new object JS

I’m playing with JS “oop” (or should i say “pop” – prototype oriented programming?) and tried to do something like static method and functions. I can call function from prototype object but that isn’t exactly static function, is it?

I have that code:

function a(val){
   this.val = val;
   console.log(this);
   this.foo = function(){
     console.log('hi');
   }
 }

And i want to call the foo function without creating a new object. Is something like this is possible? How can i do it?


Source: oop

Leave a Reply