Permalink
Browse files

Added files.

  • Loading branch information...
pazguille committed Dec 7, 2011
1 parent 9597ae5 commit 18fae793b80e44129e085b66b1a950ad6b6d4fb5
Showing with 114 additions and 0 deletions.
  1. +46 −0 index.html
  2. +68 −0 oop.js
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Oop.JS: Object Oriented JavaScript Class Library</title>
</head>
<body>
<script src="oop.js"></script>
<script>
var Animal = oop.Class("Animal")
.construct(function (name) {
this.name = name;
})
.method("sleep", function () {
alert("ZzZzZzZzZzZzZzZzZz");
})
.build();
var Cat = oop.Class("Cat")
.extends(Animal)
.method("purr", function () {
alert("purrrrrrrrrrrrr");
})
.build();
var Dog = oop.Class("Dog")
.extends(Animal)
.method("bark", function () {
alert("Wua bark woop arf");
})
.build();
var lilo = new Cat("Lilo");
var luz = new Dog("Luz");
alert(lilo.name); // Lilo
alert(luz.name); // Luz
lilo.sleep(); // ZzZzZzZzZzZzZzZzZz
luz.sleep(); // ZzZzZzZzZzZzZzZzZz
lilo.purr(); // purrrrrrrrrrrrr
luz.bark(); // Wua bark woop arf
</script>
</body>
</html>
68 oop.js
@@ -0,0 +1,68 @@
(function(window, undefined) {
var oop = (function(){
var Class = function (klass) {
var Klass, definitor;
Klass = function (conf) {
var that = this;
var conf = conf || {};
this.type = klass;
if (Klass.parent && Klass.parent.hasOwnProperty("construct")) { Klass.parent.construct.call(this, conf);
}
if (Klass.prototype.hasOwnProperty("construct")) {
Klass.prototype.construct.call(this, conf); }
return this;
};
definitor = {
"extends": (function () {
var F = function () {};
return function (Parent) {
F.prototype = Parent.prototype;
Klass.prototype = new F();
Klass.parent = Parent.prototype;
Klass.prototype.constructor = Klass;
return definitor;
}
}()),
"construct": function (func) {
Klass.prototype.construct = func;
return definitor;
},
"method": function (member, param) {
Klass.prototype[member] = param;
return definitor;
},
"build": function () {
return Klass;
}
};
return definitor;
};
var core = {
"Class": Class
};
return core;
})();
window.oop = oop;
})(window);

0 comments on commit 18fae79

Please sign in to comment.