Last active
January 18, 2018 20:43
-
-
Save jdaly13/5581538 to your computer and use it in GitHub Desktop.
update jquery end method to include parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with this you can write .end(3) instead of .end().end().end() | |
(function(){ | |
// Define overriding method. | |
jQuery.fn.end = function(no_of_times){ | |
var prevObject = this.prevObject; | |
if (!(arguments.length) || (typeof no_of_times !== "number")) { | |
return this.prevObject || this.constructor(null); | |
} else { | |
for(i = 1; i<no_of_times; i++) { | |
prevObject = prevObject.prevObject; | |
if(!prevObject) { | |
prevObject = this.constructor(null); | |
break | |
} | |
} | |
return prevObject; | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment