Required for programmers-create a js library and a required js library for programmers

Source: Internet
Author: User

Required for programmers-create a js library and a required js library for programmers

<Span style = "font-family: Arial, Helvetica, sans-serif; background-color: rgb (255,255,255 ); "> </span> <span style =" font-family: Arial, Helvetica, sans-serif; background-color: rgb (255,255,255 ); "> the construction of the Javascript method described in niujia Javascript is placed on the HTML page. On the one hand, this will expose the implementation process of your own method, second, if the same method is required for other pages, you have to re-write the same method, which cannot achieve good reuse. build a js library and introduce the src attribute using the script tag <script> </script>. The methods in JS can be called at will. not only will the implementation method not be exposed on the HTML page, but it will greatly improve the functionality. on the other hand, this is a savings accumulated by the programmer's experience. Some functions can be put in for later use. </span>

Next, write your own js library. First, prepare the template:

<span style="font-size:14px;">(function(){window['namespace']={}window[''namespace'']['function']=$; })();</span>

Note that the composite symbols must not be missed. If the source template is used, copy and paste it as much as possible to reduce the errors caused by handwriting.

Use this template to create a function:

<Span style = "font-size: 14px;"> (function () {// register a namespace IC with window. Window ['jg'] ={} function $ () {// defines an array of elements, an array object. Var elements = new Array (); // cyclically verifies the Array. Arguments is an internal object returned by js. It returns the parameter object passed by function, in the form of an array. For (var I = 0; I <arguments. length; I ++) {// defines the element Object and reads the parameter array. Var element = arguments [I]; // determines whether the original element in the array is of the string type. If (typeof element = 'string') {element = document. getElementById (element);} // if only one of the current parameters is found, this parameter is directly returned. If (arguments. length = 1) {return element;} // if there are multiple parameters. We put it in the array elements. Elements. push (element);} // Retrieves all the elements and returns them. Return elements;} // register the namespace JG with windows and register the $ method with the namespace. Window ['jg'] ['$'] =$ ;}) (); </span>
REFERENCE The JS library in the script Tag:

<Script type = "text/javascript" src = "CJG. js"> </script>Ps: src = "js file path"


Next, the method in js can be called. Call the instance:

<Span style = "font-size: 14px;"> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 





When interviewing JavaScript programmers, what knowledge must be mastered, such as software, language, and so on?

Think in java is recommended! You asked the same question many times on this page. Let's talk about it. head first java is for beginners, but it is definitely a high level after reading it.

 
Js programmer

JS programmers? What do you want to ask?
 

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.