简体   繁体   中英

Is it OK to call a regular JavaScript function within jQuery?

Is it correct to call a regular JavaScript function in a jQuery script or should it be external (it will only be access/used by the jQuery script)? I know that it works but I want to make sure that I am using best practice. For example:

$(function(){

    $('.click1').click(function(){
         dofunction();
    }

    $('.click2').click(function(){
         dofunction();
    }

    function testing(grid_array){
         alert('function works!');  
    }

});

jQuery is a JavaScript library adding facilities, most of them helping to deal with the DOM, AJAX, or crossbrowser issues. Your jQuery script is thus also a JavaScript one.

It's perfectly normal, recommended and fine to call non jQuery based functions from code made using jQuery. In fact, you could hardly avoid that.

Related: What is the difference between jQuery and JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM