Permalink
Browse files

adding package.json, etc...

  • Loading branch information...
CrabDude committed Feb 8, 2011
1 parent db95036 commit 1eaa7053b98493dc6d6972514877faed2a403479
Showing with 107 additions and 0 deletions.
  1. +43 −0 examples/automatic/automatic.js
  2. +9 −0 examples/automatic/index.html
  3. +9 −0 examples/manual/index.html
  4. +46 −0 examples/manual/manual.js
@@ -0,0 +1,43 @@
var Person = Class.extend(function(pvt) {
var chromosomes = 48; // private static
return {
init: function(isDancing) {
pvt(this).dancing = isDancing;
},
dance: function() {
return pvt(this).dancing;
},
getChromosomeCount: function() {
return chromosomes;
}
};
});
var Ninja = Person.extend(function(pvt) {
return {
init: function(hasSword){
this._super( false );
pvt(this).hasSword = hasSword || true;
},
dance: function(){
// Call the inherited version of dance()
return this._super();
},
swingSword: function(){
return pvt(this).hasSword;
}
};
});
var p = new Person(true);
console.log(p.dance()); // => true
var n = new Ninja();
console.log(n.dance()); // => false
console.log(n.swingSword()); // => true
// Should all be true
console.log(p instanceof Person && p instanceof Class &&
n instanceof Ninja && n instanceof Person && n instanceof Class);
@@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
<h1>Privates.js Example: Automatic</h1>
<script src="../../lib/privates.js"></script>
<script src="automatic.js"></script>
</body>
</html>
@@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
<h1>Privates.js Example: Manual</h1>
<script src="../../lib/privates.js"></script>
<script src="manual.js"></script>
</body>
</html>
View
@@ -0,0 +1,46 @@
var Person = Class.extend((function() {
var chromosomes = 48, // private static
pvt = Class.pvt(); // generate private instance store
return {
init: function(isDancing) {
pvt(this).dancing = isDancing;
},
dance: function() {
return pvt(this).dancing;
},
getChromosomeCount: function() {
return chromosomes;
}
};
})());
var Ninja = Person.extend((function() {
var pvt = Class.pvt();
return {
init: function(hasSword){
this._super( false );
pvt(this).hasSword = hasSword || true;
},
dance: function(){
// Call the inherited version of dance()
return this._super();
},
swingSword: function(){
return pvt(this).hasSword;
}
};
})());
var p = new Person(true);
console.log(p,p.dance()); // => true
var n = new Ninja();
console.log(n,n.dance()); // => false
console.log(n.swingSword()); // => true
// Should all be true
console.log(p instanceof Person && p instanceof Class &&
n instanceof Ninja && n instanceof Person && n instanceof Class);

0 comments on commit 1eaa705

Please sign in to comment.