Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (47 sloc) 1.204 kb
aff869a @iwyg initial commit
authored
1 # A Klass Factory
2
cc36ce3 @iwyg fixed readme
authored
3 ### Example usage
4 also see docs/jQuery.html
aff869a @iwyg initial commit
authored
5
cc36ce3 @iwyg fixed readme
authored
6 var Animal = $.factory(null, function () {
7 this.alive = true;
8 }, {
9 sleep: function () {
10 if (this.alive) return 'zzz';
11 }
12 });
aff869a @iwyg initial commit
authored
13
14
cc36ce3 @iwyg fixed readme
authored
15 var Mamel = $.factory(Animal, function (name) {
16 this.name = name || 'mamel';
17 }, {
18 breastFeeds: function () {
19 if (this.alive) return 'suckle';
20 }
21 });
22
23 var Dog = $.factory(Mamel, function () {
24 this.smells = 'badly';
25 }, {
26 bark: function () {
27 if (this.alive) return 'woof';
28 }
29 });
30
31
32 var microbe = new Animal();
33 microbe.alive // true
34 microbe.sleep(); // zzz
35
36 var higherAnimal = new Mamel('cow');
37 higherAnimal.name // cow
38 higherAnimal.alive; // true
39 higherAnimal.sleep(); // zzz
40 higherAnimal.breastFeeds(); // suckle
41
8a6461e @iwyg fixed readme
authored
42 var lucy = new Dog('lucy');
43 lucy.name // lucy
44 lucy.alive; // true
45 lucy.smells; // badly
46 lucy.sleep(); // zzz
47 lucy.breastFeeds(); // suckle
48 lucy.bark(); // woof
49
78964dc @iwyg updated readme and unit-tests
authored
50
51 // MIXINS:
52
53 $.factory(null, contructor, {
54 foo: some.prototype.foo,
55 baz: some.prototype.baz,
56 run: another.prototype.run
57 });
58
59 // OR JUST PASS PROPERTY/METHOD NAMES AND THE CORRESPONDING OBJECT
60
61 $.factory(null, contructor, 'foo baz', some.prototype);
Something went wrong with that request. Please try again.