Giter Club home page Giter Club logo

Comments (4)

mgechev avatar mgechev commented on May 13, 2024
  • According to the AngularJS documentation, there is a component called "service", which could be defined using .factory, .service or .provider. The services section summarize all ways of creating services. You're right that there might be misunderstanding so I'm going to include additional information, in order to clarify it.
  • The services defined with .service are instantiated through $injector.instantiate invoking the constructor function with the new operator (just like you said). Naming services created with .factory and ones created with .service in different way is definitely inconsistent. My suggestion is to use UpperCamelCase for services, which define constructor function, which later when the service have been injected, could be invoked with new, i.e.:
module.controller('MainCtrl', function ($scope, User) {
  $scope.user = new User('foo', 42);
});

module.factory('User', function () {
  return function User(name, age) {
    this.name = name;
    this.age = age;
  };
});
  • Klassical is intentional misspelling. Since in JavaScript we don't have classes and the "classical" OOP impossible some authors (like Stoyan Stefanov in his "JavaScript Patterns"), intentionally misspell classes with "k", I'm just following them.

from angularjs-style-guide.

mgechev avatar mgechev commented on May 13, 2024

@hansifer I did some additional changes in the "Services" section. Please, take a look and tell me whether you find it more clear and correct in order to close the issue.

from angularjs-style-guide.

hansifer avatar hansifer commented on May 13, 2024

Thanks for the quick reply and clarifications. I'm still relatively new to Angular and your explanations offer new insight.

The updates look good, thanks.

from angularjs-style-guide.

mgechev avatar mgechev commented on May 13, 2024

Thats absolutely find, everyone begins from somewhere.

Thank you a lot for the suggestions!

from angularjs-style-guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.