-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathString2.js
More file actions
45 lines (44 loc) · 1.77 KB
/
String2.js
File metadata and controls
45 lines (44 loc) · 1.77 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
// create a proxy class to wrap another
Function.prototype.wrap = function(subClass, functions){
var name = "__String";
// wrap sub-class' prototype functions
for (var i in subClass.prototype){
if (subClass.prototype[i] instanceof(Function)){
// but not instanceOf and typeOf
if (i == 'instanceOf') continue;
if (i == 'typeOf') continue;
this.prototype[i] = new Function("return " + name + ".prototype." +
i + ".apply(this." + name + ", arguments); "/* +
"this.onMethodCall(" + name + ".prototype." + i + ",arguments);"*/);
}
}
// wrap any other user specified functions
if (functions){
for (i = 0; i < functions.length; i++){
var f = functions[i];
this.prototype[f] = new Function("return " + name + ".prototype." +
f + ".apply(this." + name + ", arguments); "/* +
"this.onMethodCall(" + name + ".prototype." + f + ",arguments);"*/);
}
}
// provide default onMethodCall()
if (!this.prototype.onMethodCall){
this.prototype.onMethodCall = function(){};
}
}
function String(value){
// create String property - required by stub functions
this.Str = value ? value.toString() : '';
// implement length property
this.length = this.Str.length;
}
// inherit from Object
//String.inherit(Object);
// wrap the String class
String.wrap(__String,
['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat',
'fixed', 'fontcolor', 'fontsize', 'fromCharCode', 'indexOf', 'italics',
'lastIndexOf', 'link', 'localeCompare', 'match', 'replace', 'search',
'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring',
'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase',
'toUpperCase', 'toString', 'valueOf']);