addGetHookIf.js 509 B

12345678910111213141516171819202122
  1. define(function() {
  2. function addGetHookIf( conditionFn, hookFn ) {
  3. // Define the hook, we'll check on the first run if it's really needed.
  4. return {
  5. get: function() {
  6. if ( conditionFn() ) {
  7. // Hook not needed (or it's not possible to use it due
  8. // to missing dependency), remove it.
  9. delete this.get;
  10. return;
  11. }
  12. // Hook needed; redefine it so that the support test is not executed again.
  13. return (this.get = hookFn).apply( this, arguments );
  14. }
  15. };
  16. }
  17. return addGetHookIf;
  18. });