Search code examples
javascriptobjectjavascript-objectsprototypejs

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


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


Solution

  • 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();