source: gs3-extensions/web-audio/trunk/js-dsp/component/crockford-inheritance.js

Last change on this file was 28388, checked in by davidb, 11 years ago

Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities

File size: 1.6 KB
Line 
1
2
3Function.prototype.getHashCode = (function() {
4 var id = 0;
5 return function() {
6 if (!this["hashCode"]) {
7 this["hashCode"] = "<hash|#" + id++ + ">";
8 }
9 return this["hashCode"];
10 }
11})();
12
13var toType = function(obj) {
14 return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
15};
16
17
18Function.prototype.method = function (name, func) {
19 this.prototype[name] = func;
20 return this;
21};
22
23// Does the same as above, but explicitly rewritten here to provide more meaningful name and (variables)
24Function.prototype.staticfield = function (name, field) {
25 this.prototype[name] = field;
26 return this;
27};
28
29Function.method('inherits', function (parent) {
30 var d = {}, p = (this.prototype = new parent());
31
32 this.method('uber', function uber(name) {
33 if (!(name in d)) {
34 d[name] = 0;
35 }
36 var f, r, t = d[name], v = parent.prototype;
37 if (t) {
38 while (t) {
39 v = v.constructor.prototype;
40 t -= 1;
41 }
42 f = v[name];
43 } else {
44 f = p[name];
45 if (f == this[name]) {
46 f = v[name];
47 }
48 }
49 d[name] += 1;
50 r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
51 d[name] -= 1;
52 return r;
53 });
54
55 return this;
56});
57
58Function.method('swiss', function (parent) {
59 for (var i = 1; i < arguments.length; i += 1) {
60 var name = arguments[i];
61 this.prototype[name] = parent.prototype[name];
62 }
63 return this;
64});
Note: See TracBrowser for help on using the repository browser.