Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added files.

  • Loading branch information...
commit 18fae793b80e44129e085b66b1a950ad6b6d4fb5 1 parent 9597ae5
@pazguille authored
Showing with 114 additions and 0 deletions.
  1. +46 −0 index.html
  2. +68 −0 oop.js
View
46 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>
View
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;
Please sign in to comment.
Something went wrong with that request. Please try again.