Uncaught TypeError: lib(...).some is not a function

425 Views Asked by At

I am trying create a prototype of function using object.

var  lib = function(){
   return true;
};

lib.prototype = {
   some: () => {
      console.log("prototype is called");
   }
}

lib.some();

it's not working

1

There are 1 best solutions below

0
abdo afage On BEST ANSWER

you must define an object from lib function and use it

LIKE THIS:

var  lib = function(){
  return true;
};

lib.prototype = {
  some: () => {
     console.log("prototype is called");
  }
}

let a=new lib();

a.some();

OR use new

var  lib = function(){
  return true;
};

lib.prototype = {
  some: () => {
     console.log("prototype is called");
  }
}

new lib().some();