开发者

self executing function for javascript control

开发者 https://www.devze.com 2023-03-20 23:04 出处:网络
I am building an asp.net c# application that is heavily reliant on javascript and in pa开发者_如何学Pythonrticular jquery for usability.

I am building an asp.net c# application that is heavily reliant on javascript and in pa开发者_如何学Pythonrticular jquery for usability.

I want to go with a namespaced object oriented approach for my javascript and so far I think I have achieved such.

For example I have the following setup for my global js file with common functions.

 (function (NS, $, undefined) {

  // javascript here   

 }
 (window.NS = window.NS || {}, jQuery));

Now I want to introduce similar for my controls where I work on the basis of 1 control = 1 javascript file.

I have seen multiple ways in jquery for the self executing of the jquery function and at present I have set up my javascript controls like follows.

$(function() { 
  // javascript here
 });

What is the best approach for the controls javascript - should I set it up like the global surround - as I want to be able access my NS namespace within the controls javascript?


Set them up like this:

(function($) {
   // javascript here 
   // NS.MyOtherJs.doSomething();
}(jQuery));
0

精彩评论

暂无评论...
验证码 换一张
取 消