JavaScript: Closures help -


In this I have an empty .js file that contains this code:

  cart. CheckoutNow = {...} // alias if (TypeTouchNow) === 'undefined') {CheckoutNow = Cart.CheckoutNow; } And {warnings ('checkout now has a variable already in the window.'); }  

How can I see the // alias code at the top of the page, but it can execute after the cart. Checkout is now declared?

This will work, but I do not like that you have to call the following warning ():

  alias = function () {if (typeof ( CheckoutNow) == = 'undefined') {CheckoutNow = Cart Checkout now; } And {warnings ('checkout now has a variable already in the window.'); }}; Cart Checkout = = {...}; Aka ();  

Without explanation why you are trying to do this, I'm going I think that this is a better code for the organization. If this is the case, I will split your JavaScript into some files on this pattern, and will be included in your page in this order:

 < Code> // namespace.js if (typeof cart === 'undefined') {cart = {}; } // checkoutnow.js Cart.CheckoutNow = {// module code here} // alias.js alias = function () {// alias code here} // domready.js onDocumentReadyFunction () {alias (); }  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -