Skip to content

Instantly share code, notes, and snippets.

@kaheglar
Created June 23, 2011 12:38
Show Gist options
  • Save kaheglar/1042463 to your computer and use it in GitHub Desktop.
Save kaheglar/1042463 to your computer and use it in GitHub Desktop.
jQuery assert - throw error msg if condition false
(function($) {
$.assert = function(condition, msg) {
if (!condition) {
$.error(msg);
}
};
})(jQuery);
@kaheglar
Copy link
Author

Usage

$.assert(typeof arg === "string", "Invalid argument - string expected");

@ripper234
Copy link

The method should end with "return this".

@ripper234
Copy link

Hmm, or maybe not ... my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment