How can I get JQuery to report an error-, jquery to report an error?

Source: Internet
Author: User
Tags jquery library

How can I get JQuery to report an error-, jquery to report an error?

0. resolved issues

A. When the selector syntax is correct and no element is found, let jquery report an error.

B. When there is a problem with the selector syntax and the program cannot continue execution, let jquery report an error

It is mainly used to pass strings. Back up the jquery library before trying. It is best to change the name and add the name to be differentiated.

1. Environment Configuration

Jquery-3.0.0.js unzipped version

2. There is no problem with the selector syntax and no element can be found.

Add code to modify jquery source code. The following is the modified Code. The added code is highlighted in red.

Var version = "3.0.0", // Define a local copy of jQuery = function (selector, context) {// The jQuery object is actually just the init constructor 'enabled' // Need init if jQuery is called (just allow error to be thrown if not supported DED) if (typeof window ["[]"] = "undefined") {window ["[]"] = []; window ["[]"] ["selector"] = selector; window ["[]"] ["current"] = 0 ;} else {window ["[]"] ["current"] ++;} var c = new jQuery. fn. init (selector, context) if (window ["[]"] ["current"] -- = 0) {if (c. length = 0) {window. console. error (window ["[]"] ["selector"] + "cannot be found");} delete window ["[]"];} return c ;},

3. If the selector syntax is incorrect, the program cannot continue execution.

Code example

$ (Function ()

{

Var lol = $ ("li :");
Alert (lol. length );
});


Add code to the jquery source code based on the code added in the previous question. The following is the modified Code, and red is the added part.

 
Process = special? MightThrow: function () {try {mightThrow ();} catch (e) {if (jQuery. deferred. exceptionHook) {jQuery. deferred. exceptionHook (e, process. stackTrace);} // Support: Promises/A + section 2.3.3.3.4.1 // https://promisesaplus.com/#point-61 // Ignore post-resolution tions if (depth + 1> = maxDepth) {// Only substitute handlers pass on context // and multiple values (non-spec behavior) if (handler! = Thrower) {that = undefined; args = [e];} deferred. rejectWith (that, args);} if (typeof window ["[]"]! = "Undefined") {if (window ["[]"] ["current"] = 0) {window. console. error (window ["[]"] ["selector"] + "Preventing program execution from going down ");}}}};
As for the reason why the program cannot be executed downward, I cannot give a positive answer. JavaScript function calls always return content. When I use the debug tool to find out, the end of this function does not go. How can we say it? Come on!
Found the causeVar lol = $ ("li:"); an error is reported, resulting in program termination
Try
{
  
  var lol = $("li:");

}
catch(e)
{
  alert(e);
}
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.