Skip to content

Commit 9d4c343

Browse files
committed
added ability to pass callback functions to instance methods for chainability
1 parent 2b5c796 commit 9d4c343

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/core.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,25 @@ jStat.extend = function( obj ) {
117117
for ( var i = 0; i < funcs.length; i++ ) (function( passfunc ) {
118118

119119
// if a matrix is passed, automatically assume operation should be done on the columns
120-
jStat.fn[ passfunc ] = function( fullbool ) {
120+
jStat.fn[ passfunc ] = function( fullbool, func ) {
121121
var arr = [],
122122
i = 0,
123-
tmpthis;
123+
tmpthis = this;
124+
if ( isFunction( fullbool )) {
125+
func = fullbool;
126+
fullbool = false;
127+
}
128+
if ( func ) {
129+
setTimeout( function() {
130+
func.call( tmpthis, jStat.fn[ passfunc ].call( tmpthis, fullbool ));
131+
}, 15 );
132+
return this;
133+
}
124134
if ( this.length > 1 ) {
125-
tmpthis = this.transpose();
126-
for ( ; i < tmpthis.length; i++ ) {
135+
tmpthis = fullbool === true ? this : this.transpose();
136+
for ( ; i < tmpthis.length; i++ )
127137
arr[i] = jStat[ passfunc ]( tmpthis[i] );
128-
}
129-
if ( fullbool === true ) {
130-
arr = jStat[ passfunc ]( arr );
131-
}
132-
} else {
133-
arr = jStat[ passfunc ]( this[0] );
138+
arr = fullbool === true ? jStat[ passfunc ]( arr ) : arr;
134139
}
135140
return arr;
136141
};
@@ -140,8 +145,16 @@ jStat.extend = function( obj ) {
140145
// extend jStat.fn with methods that have no argument
141146
(function( funcs ) {
142147
for ( var i = 0; i < funcs.length; i++ ) (function( passfunc ) {
143-
jStat.fn[ passfunc ] = function() {
144-
var results = jStat[ passfunc ]( this );
148+
jStat.fn[ passfunc ] = function( func ) {
149+
var tmpthis = this,
150+
results;
151+
if ( func ) {
152+
setTimeout( function() {
153+
func.call( tmpthis, jStat.fn[ passfunc ].call( tmpthis ));
154+
}, 15 );
155+
return this;
156+
}
157+
results = jStat[ passfunc ]( this );
145158
return isArray( results ) ? jStat( results ) : results;
146159
};
147160
})( funcs[i] );
@@ -150,7 +163,14 @@ jStat.extend = function( obj ) {
150163
// extend jStat.fn with methods that require one argument
151164
(function( funcs ) {
152165
for ( var i = 0; i < funcs.length; i++ ) (function( passfunc ) {
153-
jStat.fn[ passfunc ] = function( arg ) {
166+
jStat.fn[ passfunc ] = function( arg, func ) {
167+
var tmpthis = this;
168+
if ( func ) {
169+
setTimeout( function() {
170+
func.call( tmpthis, jStat.fn[ passfunc ].call( tmpthis, arg ));
171+
}, 15 );
172+
return this;
173+
}
154174
return jStat( jStat[ passfunc ]( this, arg ));
155175
};
156176
})( funcs[i] );

0 commit comments

Comments
 (0)