0

When I run my app there is an error `

"Uncaught TypeError: object is not a function", source: file:///android_asset/www/js/controller.js (2)

I have a class model.js :

var posAttuale = {
    myLat : "myLat",
    myLng : "myLng",
    myComune : "myComune"
};

and a class controller.js :

    var infoPos = new posAttuale; //Error is here
   //....rest of program....

How can I fix the error?

`

1
  • Well like the error says its not a function, its an object, you cannot call new on it Commented Jun 18, 2015 at 9:26

1 Answer 1

3

You need to call it as a constructor, and define it as a constuct function:

var posAttuale = function() {
    this.myLat = "myLat";
    this.myLng = "myLng";
    this.myComune = "myComune";
};

var infoPos = new posAttuale();
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't notice that you first define posAttuale as object, so I didn't alter it. Now I just changed all your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.