-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
50 lines (50 loc) · 1.58 KB
/
example.js
File metadata and controls
50 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
angular.module('App', ['BaseClass'])
.factory('Mammal', ['BaseClass', function (BaseClass) {
return BaseClass.extend({
setAge: function (age) {
this.age = age;
},
getAge: function () {
return this.age;
}
});
}])
.factory('Dog', ['Mammal', function (Mammal) {
return Mammal.extend({
constructor: function () {
this._super('constructor', arguments);
},
setAge: function (age) {
this._super('setAge', age + 10);
},
getAge: function () {
return 'Dog is ' + this._super('getAge') + ' years old';
}
});
}])
.factory('MammalMixin', [function () {
return {
grow: function (number) {
this.age += number;
},
getName: function () {
return this.name;
}
};
}])
.factory('Cat', ['Mammal', 'MammalMixin', function (Mammal, mammalMixin) {
return Mammal.extend({
constructor: function (args) {
this._super('constructor', args);
this.name = args.name;
},
mixins: [mammalMixin]
});
}])
.controller('Ctrl', ['$scope', 'Dog', 'Cat', function ($scope, Dog, Cat) {
$scope.dog = new Dog({age: 3, name: 'Max'});
$scope.cat1 = new Cat({age: 5, name: 'Meow'});
$scope.cat1.grow(5);
$scope.cat2 = new Cat({age: 5, name: 'Meow'});
$scope.cat2.grow(5);
}]);