API Docs for: 0.0.1
Show:

File: src/js-ext/lib/function.js

  1. /**
  2. *
  3. * Pollyfils for often used functionality for Functions
  4. *
  5. * <i>Copyright (c) 2014 ITSA - https://github.com/itsa</i>
  6. * New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
  7. *
  8. * @module js-ext
  9. * @submodule lib/function.js
  10. * @class Function
  11. *
  12. */
  13.  
  14. "use strict";
  15.  
  16. require('polyfill/polyfill-base.js');
  17.  
  18. var NAME = '[Function]: ';
  19.  
  20. (function(FunctionPrototype) {
  21. /**
  22. * Sets the context of which the function will be execute. in the
  23. * supplied object's context, optionally adding any additional
  24. * supplied parameters to the end of the arguments the function
  25. * is executed with.
  26. *
  27. * @method rbind
  28. * @param [context] {Object} the execution context.
  29. * The value is ignored if the bound function is constructed using the new operator.
  30. * @param [args*] {any} args* 0..n arguments to append to the end of
  31. * arguments collection supplied to the function.
  32. * @return {function} the wrapped function.
  33. */
  34. FunctionPrototype.rbind = function (context /*, args* */ ) {
  35. console.log(NAME+'rbind');
  36. var thisFunction = this,
  37. arrayArgs,
  38. slice = Array.prototype.slice;
  39. context || (context = this);
  40. if (arguments.length > 1) {
  41. // removing `context` (first item) by slicing it out:
  42. arrayArgs = slice.call(arguments, 1);
  43. }
  44.  
  45. return (arrayArgs ?
  46. function () {
  47. // over here, `arguments` will be the "new" arguments when the final function is called!
  48. return thisFunction.apply(context, slice.call(arguments, 0).concat(arrayArgs));
  49. } :
  50. function () {
  51. // over here, `arguments` will be the "new" arguments when the final function is called!
  52. return thisFunction.apply(context, arguments);
  53. }
  54. );
  55. };
  56.  
  57. }(Function.prototype));
  58.