likuku
likuku

Reputation: 358

'not a function error'

I wrote the following logic

'use strict';
function F5 () {
}

F5.prototype.bang = function()
{
    console.log("pew pew");    
}

F5.bang();

execution falls short saying that 'F5.bang is not a function'

but it is. what did I write wrong?

Upvotes: 0

Views: 37

Answers (1)

Kevin Hoerr
Kevin Hoerr

Reputation: 2609

Since F5 is a prototype, it must be initialized as an object in order to use prototype methods on F5. For example:

var abc = new F5();

abc.bang(); // pew pew

Upvotes: 1

Related Questions