Skip to content

Commit

Permalink
Added files.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazguille committed Dec 7, 2011
1 parent 9597ae5 commit 18fae79
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
46 changes: 46 additions & 0 deletions index.html
@@ -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 changes: 68 additions & 0 deletions 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);
Expand Down

0 comments on commit 18fae79

Please sign in to comment.