Javascript page templated-methods not used by most people

Source: Internet
Author: User

 Introduction
 
I encountered a problem today. This problem is also a problem I encountered before. The previous method is also used by most people. You can read my article.
 
Previous Method--I guess this is also the way most people use it.
 
For example, the following code is taken from a piece of js Code on the Sina homepage. This method is also used by most people.

What did you do after reading the above Code? You may change the form of + = to the push form of the array. Some people say that push is faster than this character link, but it is not much faster.
 If the embeddedHtmlThere are a lot of code. do you want to handle it like this? If you modify (add or delete)HtmlSo you need to constantly flip the code, find the corresponding tag, and then find the end tag. Do you not feel the trouble? Some people may write like this (this is what I wrote earlier, and it is also my most used method ).
 


 
The above code is also very difficult to maintain. Many times, if a tag is added to the ui or the html structure is modified, it is a headache for me.
 

Page templated--New Method
 
I recently read facebook's js Code. By chance, I found that the following method looks good and I hope to share it with you.
 
View my index.html code

View my js Code

 
Today, I accidentally discovered that this method is more reasonable, because the for loop is too disturbing.

 Maintain the precedingHtmlThe code is very easy.HtmlIt is easy to change the code structure.
 

Summary

The above code has many problems. Don't be surprised. This is just my simple version.
The current template only supports simple variable replacement, and many functions are not developed, such as the if tag and for tag. if you are interested, try it. if it is successful, let me know. If we can build an open-source framework similar to smarty, we can also make some contributions to the open-source business.
 
Recommendation
 







From Chuan Shan Jia

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.