JS TypeError: is not a function

Viewed 3293

I have situation as follows

function Field(data){
    var name = data.name;
    this.foo = function(){
        console.log("foo");    
    }
}
...
field = new Field(someData);
...
console.log(field.name); //returns its name as expected
field.foo(); //TypeError: field.foo is not a function

What's problem with that? I use it in angularjs application.

Im backend developer so please be understanding.

1 Answers
Related