Repository navigation
Expand file tree
/
Copy pathcore.js
More file actions
79 lines (73 loc) · 2.14 KB
/
Copy pathcore.js
File metadata and controls
79 lines (73 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// CORE module, abstracts environment-specifics
var CORE = function(){
/*
* blatantly ripped off from Douglas Crockford
*/
var modifyLanguage = function(){
Function.prototype.method = function (name, func) {
if (!this.prototype[name]){
this.prototype[name] = func;
return this;
}
};
Function.method('inherits', function(Parent){
this.prototype = new Parent();
return this;
});
Array.method('each', function(f, index){
for (var i=0; i<this.length; i++){
f(this[i], i);
}
});
Array.method('reduce', function(f, value){
this.each(function(item){
value = f(item, value);
});
return value;
});
Array.method('contains', function(test){
var contains = false;
this.each(function(item){
if (item === test){
contains = true;
return false;
}
});
return contains;
});
Object.create = function(o){
var F = function(){};
F.prototype = o;
return new F();
};
Object.mixin = function(obj,mixin){
for (name in mixin){
if (mixin.hasOwnProperty(name)){
obj[name] = mixin[name];
}
}
return obj;
};
};
modifyLanguage();
return {
out : function(output){
//implemented by env
},
require : function(toImport){
this.out("'require' not implemented!");
},
debug : function(a, deep){
this.out( a + ', typeof ' + typeof a);
for (var name in a){
if (deep || (a.hasOwnProperty(name))){
if (typeof a[name] === 'function'){
this.out(name + ': [a method]');
} else {
this.out(name + ':' + a[name]);
}
}
}
}
};
}();