Created
August 5, 2016 23:00
-
-
Save nakana/7e449b86673cdd53e2711364f47f523f to your computer and use it in GitHub Desktop.
Angularのファクトリとサービスの違い ref: http://qiita.com/nakana/items/31552f903af728175707
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('hoge') | |
.factory('hogeFactory', function(){ | |
function func1 (){} | |
function func2 (){} | |
function func3 (){} | |
return { | |
func1: function(){ | |
return func1(); | |
}, | |
func2: function(){ | |
return func2(); | |
}, | |
func3: function(){ | |
return func3(); | |
}, | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function functionName (){} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var functionName = function(){} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('hoge') | |
.factory('hogeFactory', function(){ | |
function func1 (){} | |
function func2 (){} | |
function func3 (){} | |
return { | |
func1: func1, | |
func2: func2, | |
func3: func3, | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('hoge') | |
.service('hogeService', function(){ | |
this.func1 = function(){}: | |
this.func2 = function(){}: | |
this.func3 = function(){}: | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(name, age){ | |
this.name = name; | |
this.age = age; | |
this.introduce = function(){ console.log(this.name + 'です。' + this.age + '才です。'); }; | |
this.jump = function(){ console.log('ぴょーん'); }; | |
this.eat = function(){ console.log('ぱっくん'); }; | |
} | |
var taro = new Person('太郎', 10); | |
taro.introduce(); | |
taro.eat(); | |
taro.jump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function person(name, age){ | |
var object = {}; | |
object.name = name; | |
object.age = age; | |
object.introduce = function(){ console.log(this.name + 'です。' + this.age + '才です。'); }; | |
object.jump = function(){ console.log('ぴょーん'); }; | |
object.eat = function(){ console.log('ぱっくん'); }; | |
return object; | |
} | |
var taro = person('太郎', 10); | |
taro.introduce(); | |
taro.eat(); | |
taro.jump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function person(name, age){ | |
function introduce(){ console.log(this.name + 'です。' + this.age + '才です。'); }, | |
function jump(){ console.log('ぴょーん'); }, | |
function eat(){ console.log('ぱっくん'); }, | |
return { | |
name: name, | |
age: age, | |
introduce: introduce, | |
jump: jump, | |
eat: eat | |
}; | |
var taro = person('太郎', 10); | |
taro.introduce(); | |
taro.eat(); | |
taro.jump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('hoge') | |
.service('hogeService', function(){ | |
this.func1 = function(){}: | |
this.func2 = function(){}: | |
this.func3 = function(){}: | |
}) | |
.factory('hogeFactory', function(){ | |
function func1 (){} | |
function func2 (){} | |
function func3 (){} | |
return { | |
func1: func1, | |
func2: func2, | |
func3: func3, | |
}; | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment