XML DOM, XPath and XMLHttpRequest support for O::U::SpiderMonkey
[Evergreen.git] / Open-ILS / src / javascript / backend / libs / jsOO.js
1 Function.prototype.method = function (name, func) {
2     this.prototype[name] = func;
3     return this;
4 }
5
6 Function.method('inherits', function (parent) {
7     var d = 0, p = (this.prototype = new parent());
8     this.constructor = this;
9     this.prototype.superclass = parent;
10     this.method('uber', function uber(name) {
11         var f, r, t = d, v = parent.prototype;
12         if (t) {
13             while (t) {
14                 v = v.constructor.prototype;
15                 t -= 1;
16             }
17             f = v[name];
18         } else {
19             f = p[name];
20             if (f == this[name]) {
21                 f = v[name];
22             }
23         }
24         d += 1;
25         r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
26         d -= 1;
27         return r;
28     });
29     return this;
30 });
31
32
33 instance_of = function(o, c) {
34         while (o != null) {
35                 if (o.constructor === c) {
36                         return true;
37                 }
38                 if (o === Object) {
39                         return false;
40                 }
41                 o = o.superclass;
42         }
43         return false;
44 };
45
46