-
Notifications
You must be signed in to change notification settings - Fork 421
/
construct.html
78 lines (68 loc) · 1.76 KB
/
construct.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<title>can.Construct Demo</title>
</head>
<body>
<h1>Some can.Construct demos</h1>
<p>Open the console to see the status messages.</p>
<script type='text/javascript' src="../node_modules/steal/steal.js" main="@empty"></script>
<script type='text/javascript' id="demo-source">
console.log("HERE")
steal(function() {
steal.config({
root: '../'
});
}).then('can/construct', function(Construct){
var Animal = Construct({
breathe : function () {
console.log('Breathing');
}
});
var man = new Animal();
man.breathe(); // -> Breathing
man instanceof Animal //-> true
Dog = Animal({
bark : function () {
console.log('Woof!');
}
});
var dog = new Dog;
dog.bark(); // Woof!
dog.breathe(); // Breathing
var Person = Construct({
init : function (name) {
this.name = name;
},
speak : function () {
return "I am " + this.name + ".";
}
});
var payal = new Person("Payal");
console.log(payal.speak()); // -> I am Payal.
var Person = Construct({
count : 0
}, {
init : function(name) {
this.name = name;
this.constructor.count++;
}
});
var justin = new Person('Justin'),
brian = new Person('Brian');
console.log(Person.count); // -> 2
Construct("Bitovi.Person", {
init : function(name) {
this.name = name;
}
});
console.log(Bitovi.Person.shortName); // -> 'Person'
console.log(Bitovi.Person.fullName); //-> 'Bitovi.Person'
console.log(Bitovi.Person.namespace); //-> Bitovi
var person = new Bitovi.Person();
console.log(person.constructor.shortName); // -> 'Person'
console.log(person.constructor.name); // -> 'Person'
});
</script>
</body>
</html>