Zack Lucky Zack Lucky - 5 months ago 8x
Javascript Question

Type error primeFactors.for is not a function

I've got a 'TypeError: primeFactors.for is not a function' error from Jasmine when I try to run this code, I've run into this type of error so many times. What's the best way to resolve it? I know that clearly .for is not a function but I'm not sure why?

var primeFactors = function(){};

primeFactors.prototype.for = function(num){
var array = [];
for(var i = 2; i < Math.ceil(Math.sqrt(num)); i++){
if(num % i === 0){
num = num/i;
return array;

module.exports = primeFactors;


When you want to call .for, you must create an object instance for that prototype, for instance with the new keyword:

This is not OK:


But this is OK:

 var obj = new primeFactors;

For your Jasmine test, it would work like this:

 it('returns an empty array for 1', function() {
     expect((new primeFactors).for(1)).toEqual([]);