Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added append and prepend to Function prototype

  • Loading branch information...
commit 33ed96557545804f57fd545dc4e80cd2928da909 1 parent f89d814
Jan Dolecek authored January 13, 2011

Showing 1 changed file with 50 additions and 1 deletion. Show diff stats Hide diff stats

  1. 51  src/prototype/lang/function.js
51  src/prototype/lang/function.js
@@ -376,6 +376,53 @@ Object.extend(Function.prototype, (function() {
376 376
       return __method.apply(null, a);
377 377
     };
378 378
   }
  379
+  
  380
+  /**
  381
+   * Function#append(cb1, [cb2, ...]) -> Function
  382
+   *
  383
+   * Append another callbacks after a function
  384
+  **/
  385
+  function append() {
  386
+  	var __method = this, args = $A(arguments);
  387
+
  388
+  	return function() {
  389
+  		// Call main function
  390
+  		var r = __method.apply(this, arguments);
  391
+  		if(typeof r != 'undefined' && !r) return r;
  392
+
  393
+  		// Call the others
  394
+  		for(var i = 0; i < args.length; i++) {
  395
+  			if(typeof args[i] != 'function') continue;
  396
+
  397
+  			r = args[i].apply(this, arguments);
  398
+  			if(typeof r != 'undefined' && !r) return r;
  399
+  		}
  400
+  	};
  401
+  }
  402
+
  403
+  /**
  404
+   * Function#append(cb1, [cb2, ...]) -> Function
  405
+   * Prepend callbacks to be executed before this function
  406
+  **/
  407
+  function prepend() {
  408
+  	var __method = this, args = $A(arguments);
  409
+
  410
+  	return function() {
  411
+		var r;
  412
+
  413
+  		// Call the others functions
  414
+  		for(var i = 0; i < args.length; i++) {
  415
+  			if(typeof args[i] != 'function') continue;
  416
+
  417
+  			r = args[i].apply(this, arguments);
  418
+  			if(typeof r != 'undefined' && !r) return r;
  419
+  		}
  420
+
  421
+  		// Call main function
  422
+  		r = __method.apply(this, arguments);
  423
+  		if(typeof r != 'undefined' && !r) return r;
  424
+  	};
  425
+  }
379 426
 
380 427
   return {
381 428
     argumentNames:       argumentNames,
@@ -385,7 +432,9 @@ Object.extend(Function.prototype, (function() {
385 432
     delay:               delay,
386 433
     defer:               defer,
387 434
     wrap:                wrap,
388  
-    methodize:           methodize
  435
+    methodize:           methodize,
  436
+    append:              append,
  437
+    prepend:             prepend
389 438
   }
390 439
 })());
391 440
 

0 notes on commit 33ed965

Please sign in to comment.
Something went wrong with that request. Please try again.