can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
73 lines (63 loc) • 1.71 kB
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">
steal('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>