title: What is the correct way to instantiate an object in angular through factory?
body: <p>I recently read the <a href="https://github.com/johnpapa/angular-styleguide" rel="nofollow">Angular Style Guide</a> and I still wonder what are the good practices for instantiate an Object like this one :</p>
  
  <pre><code>Tracker = function(data){
    key: data.key,
    name: data.name,
    buckets: data.buckets,
    enable: data.enable || false,
    geoip: data.geoip || false
  }
  </code></pre>
  
  <p>My goals is to respect the principe of decoupling. I don't want any <code>new Tracker()</code> in my controller.</p>
  
  <p>Based to the <a href="https://github.com/johnpapa/angular-styleguide" rel="nofollow">Angular Style Guide</a> I use a factory to decoupling my controller from the class Tracker. Here is my factory.</p>
  
  <pre><code>  angular
    .module('ranger')
    .factory('factoryTracker', factoryTracker);
  
  factoryTracker.$inject = ['$anyInjetable'];
  
  function factoryTracker($anyInjetable) {
    var factory = {
      instantiate: instantiate
    };
  
    return factory;
    ///////////
  
    function instantiate(data){
      return {
        //Properties
        key: data.key,
        name: data.name,
        buckets: data.buckets,
        enable: data.enable || false,
        geoip: data.geoip || false
        //Methods
        helloWorld: helloWorld
      };
    }
  
    function helloWorld(){
        return "I come in peace";
    }
  }
  </code></pre>
  
  <p>In my controller I use it with:</p>
  
  <pre><code>factoryTracker.instantiate({
                  key: tracker._id,
                  name: tracker.name,
                  enable: false
              });
  </code></pre>
  
  <p>My problem is the way of my Tracker object is declared :</p>
  
  <ul>
  <li><p>is not really declared, we only see the implementation</p></li>
  <li><p>not easy to read </p></li>
  <li><p>implemented methods are outside the object closure...</p></li>
  <li><p>Most important: if I want to switch the class to instantiate so I don't want to write it in the factory.</p></li>
  </ul>
  
  <p>I came to this regarding several sources on using factories and where to put models. But I am not OK with my code for now.</p>
  
  <p>Any advices ?</p>