Objects in javascript

Asked

Viewed 54 times

3

When we work with objects in javascript, and with the Angularjs framework, where we write the code of the objects?

For example, I’m going to create an object that looks something like this:

var LogMessage = function(system, type, message, value, now) {
    this.system = system;
    this.type = type;
    this.message = message;
    this.value = value;
    this.time = now;
};

If I need to use it in several services or controllers, I would have to copy the code everywhere, so I should create a js file that has all my objects ?

1 answer

0

What you can do is create it in a JS file that is loaded before all others, and always loaded as well. So you can always use it. Ex:

http://jsfiddle.net/BRWPM/1836/

  • 4

    Julyano, this answer is more of a comment than a response. If you don’t have a concrete example of how to use these objects inside the Angular I suggest leaving only as a comment. If you want to [Edit] and improve, excellent :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.