Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

79 lines (70 sloc) 1.858 kb
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="cc/extend.js"></script>
</head>
<body>
<p>cc.extend test</p>
</body>
<script type="text/javascript">
var logPane = document.getElementsByTagName('body')[0]
function log(arg) {
var newLine = document.createElement('div')
newLine.innerHTML = arg
logPane.appendChild(newLine)
}
// var Animal = cc.Class.extend({
cc.module('Animal').parent('cc.Class').jClass({
type: "animal",
init: function() { log("birth of " + this.type) },
talk: function(word) { log("..." + word + "...") },
hug: function() { log("none for you") }
})
cc.module('Cat').defines(function() {
this.set(Animal.extend({
type: "cat",
likes: { mice: 1, dogs: 0 },
talk: function(word) {
this.parent(word)
log("hiss")
}
}))
})
// hook into cc module class system to create class
cc.module('HouseCat').parent('Cat').jClass({
init: function() {
log("controlled birth")
this.parent();
},
type: "friendly cat",
friend: new Cat(),
talk: function(word) {
log("meow")
this.parent(word)
}
})
log("<hr/>")
var houseCat = new HouseCat
log(houseCat instanceof Animal)
houseCat.talk(houseCat.type + ': mose')
log("<hr/>")
var cat = new Cat
cat.talk(cat.type + ': skrr')
log("<hr/>")
++cat.likes.dogs
log(houseCat.likes.dogs) // 0.. as each object has clone
Cat.inject({
hug: function() {
log(this.type + ": usually not")
this.parent()
}
}).inject({
hug: function() {
this.parent()
log(this.type + ": but sometimes")
}
})
log("<hr/>")
houseCat.hug()
</script>
</html>
Jump to Line
Something went wrong with that request. Please try again.