Skip to content

Instantly share code, notes, and snippets.

@nakana
Created August 5, 2016 23:00
Show Gist options
  • Save nakana/7e449b86673cdd53e2711364f47f523f to your computer and use it in GitHub Desktop.
Save nakana/7e449b86673cdd53e2711364f47f523f to your computer and use it in GitHub Desktop.
Angularのファクトリとサービスの違い ref: http://qiita.com/nakana/items/31552f903af728175707
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();
},
};
});
function functionName (){}
var functionName = function(){}
angular
.module('hoge')
.factory('hogeFactory', function(){
function func1 (){}
function func2 (){}
function func3 (){}
return {
func1: func1,
func2: func2,
func3: func3,
};
});
angular
.module('hoge')
.service('hogeService', function(){
this.func1 = function(){}:
this.func2 = function(){}:
this.func3 = function(){}:
});
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();
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();
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();
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