Millet company JavaScript closed-pack face testOne, please define such a function
The code is as follows
Copy Code
function repeat (func, times, wait) {}This function can return a new function, such as using thevar
In JavaScript, creating an array can use the array constructor, or use the array direct amount [], which is the preferred method. The array object inherits from the Object.prototype, and the array performs the typeof operator to return object
45 useful JavaScript tips, tips and best practices
Translator: Dwqs
In this article, I'll share some of the techniques, tips, and best practices that are commonly used in JavaScript. Whether JavaScript developers are using the browser/engine or
The first, using Math.Round
The code is as follows
Copy Code
var original=28.4531)//round "original" to two decimalsvar result=math.round (original*100)/100; Returns 28.452)//Round "original" to 1 decimalvar
For
Loops a section of code to a specified number of times
While
Loops execute code when the specified condition is true
For loop
Use a For loop when the number of times the script is run is determined.
Grammar:
for (variable = start value;
Format is day/month/year
The code is as follows
Copy Code
Date format[' Date_au ', function (v) {if (vanadium.validators_types[' empty '].test (v)) return true;var regex =/^ (d{2})/(D{2})/(d{4}) $/;if (!regex.test (v))
The code is as follows
Copy Code
Document.body.offsetWidthDocument.body.offsetHeight
In a browser that declares DOCTYPE, you can use the following to get the browser display window size:
The code is as follows
The following code, how long will the ' end ' pop up? Why?
The code is as follows
Copy Code
var t = true;settimeout (function () {t = false;}, 1000);while (t) {}Alert (' End ');
This is an implementation that
The code is as follows
Copy Code
/*** Convert string to date Object* Parameter: Date string For example: 2011-04-19 or 19/04/2011* Return: Date Object dates* Note: IE does not support direct instantiation of date objects, such as new
Number.tofixed (x) is the x bit after the specified number is intercepted, and number.toprecision (x) intercepts the entire number to the specified (x) length. Note that one calculates the length of the decimal point, and one is the length of the
Performance improvement and analysis of Web page special effects undefined
At work we often need to determine whether a variable/attribute is undefined. There are usually two ways of writing1//Mode 12 typeof age = = ' undefined ';34//Mode 25 Age = =
Web page effects implement XML and string transform each otherThese two functions are more practical ah, you can implement XML and string to transform each other Oh, there is a lot of it to deal with the XML and characters is very convenient.
Conditional statementWhen you write code, you often need to perform different behaviors according to different conditions. You can use conditional statements in your code to accomplish this task.
In JavaScript, we can use the following conditional
When a Web page effects object is generated:
such as: function BB (a) {This.a= "KKK"}
var b=new bb ();At this time B is the object has the BB attribute prototype to the prototype object;The prototype object has a constructor attribute pointing to
Tip: you can modify some code before running A good boy, Kobe, joined the Communist Party and lost memories of pig.· International News: international news· International News: international news· International News: international news·
Console commands are used to debug Web pages. During javascript development and debugging, we often use commands such as console. log () to display output information. The console panel of modern browsers (generally F12 can be called out) can help
SetTimeout ()SetTimeout () is the method of window, but we all skip the top-level object name of window. This is used to set a time. When the time is reached, a specified method will be executed. Let's take a look at the next simple example. This is
Calendar-Converter is a simple plug-in that may only be used by Chinese applications or websites. The plug-in function is to convert the date and time between the Gregorian Calendar and the lunar Calendar.ExampleFirst introduce the plug-in fileThen
Number () is used to convert numbers, String () is used to convert strings, and Boolean () is used to convert Boolean values.JavaScript data typeThere are five data types that can hold values in JavaScript:· String· Number· Boolean· Object·
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