AngularJSのFactoryとServiceをCoffeeScriptのclassを使うとこう書ける。
# factory
angular.module('myApp').factory 'HogeFactory', [
'$injection'
($injection) ->
class HogeFactory
constructor: ->
{
create: -> new HogeFactory
}
]
# service
angular.module('myApp').service 'FugaService', [
'$injection'
class FugaService
constructor: ($injection) ->
]
- Factory: インスタンスを生産する機能を持ったオブジェクト
- Service: インスタンス
というかんじでFactoryとServiceの違いを理解しやすくなる気がしている。