return acc;
},
- 'map' : function map( fn, context ){
- var o = this._o, acc = new o.constructor();
+ 'map' : function map( fn ){
+ var o = this._o
+ , cxt = arguments[1] || this
+ , acc = new o.constructor()
+ ;
for ( var name in o )
- acc[name] = fn.call( context || this, o[name], name, o );
+ acc[name] = fn.call(cxt, o[name], name, o);
return acc;
},
'forEach' : function forEach( fn, context ){
- var o = this._o;
+ var o = this._o, cxt = arguments[1] || this;
for ( var name in o )
- fn.call( context || this, o[name], name, o );
+ fn.call(cxt, o[name], name, o);
+ return this;
},
'filter' : function filter( fn, context ){
}
core.extend(this, {
- init : function init(o){
+ 'init' : function init(o){
if (!o) o = "";
this._o = o;
},
+ 'clone' : function clone(){
+ return YString(this._o);
+ },
+
/**
* As Array.slice -- replaces `howMany` elements starting at `idx`
* with the concatenation of the rest of the arguments.
*
* Invalid values for `howMany` will be replaced with 0.
*/
- splice : function splice(idx, howMany){
+ 'splice' : function splice(idx, howMany){
var s = this._o;
idx = (idx < 0 ? s.length+idx : idx);
*
* Negative values for start and/or end are allowed.
*/
- mutate : function mutate(start, end){
+ 'mutate' : function mutate(start, end){
// var args = slice.call(arguments);
arguments[1] = end-start;
return this.splice.apply(this, arguments);
},
- strip: function strip(){
+ 'strip': function strip(){
return this._o.replace(/(^\s+|\s+$)/g, '');
},
- trim: trim,
- ltrim: trim,
+ 'trim' : trim,
+ 'ltrim' : trim,
- rtrim: function rtrim(val){
+ 'rtrim' : function rtrim(val){
var s = this._o+'';
val = val+'';
return s;
},
- startsWith: function startsWith(val){
+ 'startsWith' : function startsWith(val){
return this._o.indexOf(val) === 0;
},
- endsWith: function endsWith(val){
+ 'endsWith' : function endsWith(val){
var s = this._o;
return s.lastIndexOf(val) === (s.length - val.length);
},
- compare : function compare(n){
+ 'compare' : function compare(n){
var m = this._o;
return (m > n ? 1 :
(m < n ? -1 : 0 ));
},
- toString: function(){
+ 'toString' : function(){
return this._o;
}
});
- this.set = function set(key, value, def){
+ this['set'] =
+ function set(key, value, def){
var s = this._o, _val = (value !== undefined ? value : def);
if ( isNumber(key) )
return this;
};
- this.attr = function attr(key, value, def){
+ this['attr'] =
+ function attr(key, value, def){
var s = this._o;
// set
if ( value !== undefined || def !== undefined )
};
this.attr.__wraps__ = del.attr;
- this.reduce = function reduce(fn, acc){
+ this['reduce'] =
+ function reduce(fn, acc){
fn = Function.toFunction(fn);
for ( var s = this._o, cxt = arguments[2]||this, i = 0, L = s.length; i < L; ++i )
acc = fn.call(cxt, acc, s.charAt(i), i, s);
return acc;
};
+ this['map'] =
+ function map(fn){
+ fn = Function.toFunction(fn);
+ for ( var s = this._o, L = s.length, cxt = arguments[1]||this, acc = new Array(L), i = 0; i < L; ++i )
+ acc[i] = fn.call(cxt, s.charAt(i), i, s);
+ return acc;
+ };
+
+ this['forEach'] =
+ function forEach(fn){
+ fn = Function.toFunction(fn);
+ for ( var s = this._o, L = s.length, cxt = arguments[1]||this, i = 0; i < L; ++i )
+ fn.call(cxt, s.charAt(i), i, s);
+ return this;
+ };
+
});