ecma5 fifth edition standard
ecma6 strict mode
function max () { M1 = 10; // no var, global variables are used as variables is used, } function max () { "use strict" M1 = 10; // strict mode, no var, for error, strictly mode only work under the current scope, do not use strict mode in global mode }
the indexOf ();
array,
the indexOf (element start index);
forEach ();
iterate
arr.forEach (function (element currently traversed, the current iteration of the subscript, current array) {});
var ARR = [10,20,30 ]; arr.forEach ( function (Item, index, Arrey) { Alert (Item + "," + index + "," + Arrey);}); // Returns 10,0 , 10,20,30, followed by 3 cycles arr.forEach (Alert); // returns three 10,20,30
Map ();
arr.map (function (element currently traversed, the current iteration of the subscript, current array),
traversing the "operation" return
arr.map ( function (Item, index, Arrey) { // iterate return Item + 2;}); // Returns
reduce ();
merge,
arr.reduce ( function (pre, next, index, Arrey);
pre
next iteration of the return value of the element,
Next
current traversing element, that if
reduce
passed in the parameter, the
pre
into parameters,
next
become the first element
arr.reduce ( function () { Alert (pre + "," + Next); return pre + Next; }); // first return 10, 20, 30, 30 a second return
filter ()
; filtered
arr.filter (function (element currently traversed, the current iteration of the subscript, current array),
traversing the "operation" return
var arr2 is arr.filter = ( function (Item, index, Arrey) { // iterate return Item> 10;}); // operating element 10 is greater than the return
some ()
; operation returns
to true
,
to false
arr.some ( function (Item, index, Arrey) { // iterate return Item == 10;}); // equal operating element 10 returns true, false, the matching is successful, judgment is not performed later
every ();
and
some
similar, but each must comply before returning
true
Math object
; used to perform mathematical tasks, often,
Math.PI 3.14159
round ()
; rounded
Math.round (3.4);
return 3
random();
max ();
return larger value
min ();
return smaller value
ABS ();
return the number of the absolute value,
the Math.abs (-10);
return 10
ceil ();
rounded up,
Math.ceil (3.1);
return 4
Floor ()
; rounded down
POW ();
several powers,
POW (X, y);
X is the power of y
sqrt ()
; open squares,
the Math.sqrt (. 4);
Back 2
Pythagorean theorem:
Math.sin (); Math.cos ();
Math.tan (); sine / cosine / tangent, parameters are curvature,
Math.PI = 180 [rad
, a
rad = Math.PI / 180
Alert (Math.sin, (Math.PI * 30/180 [));
SiN value of 30 degrees, should be 0.5, calculations are 0.4999, which is itself a computer bug, no solution, a partial count of the bank, without a decimal point.
Object
: is a type of complex data type / reference type, method name address, also commonly referred to as a class,
the ECMAscript
although the object-oriented language, but the language is not provided with a data structure of a conventional supported classes
Stored data objects, called function attributes, object storage, said method
var Person = new new Object (); // create, may be omitted new new, var Person = {}; // same as above PERSON.NAME = "DSF"; // Add Property person [ "name"] = " fd" ; // same as above person.showName = function () {Alert (PERSON.NAME);} // Add method Delete PERSON.NAME; // Delete key
Date Object
var D = new new a Date (); // Returns a current time, var D = new new a Date ( "2015/5/22"); // can pass parameters "2011-2-3", 2011,03,03 , 14, 23 passed in milliseconds, birth date from 1970 unix since the beginning of 1000,
Several methods of date
d.toDateString();
d.toLocalDateString();
Get day of the week or month are starting from zero subscript Sunday on behalf of 0,
d.getDay ();
Sunday returns 0
Date.parse ( "2015-2-3");
Date format, the return value, the number of milliseconds since 1970,
d.getTime () / d.setTime (),
Get Set the number of milliseconds since 1970,
function showdate (n-) { var D = new new a Date (); // Create an object var DA = d.getDate (); // get the current date d.setDate (n-DA +); // add a parameter date return D; // return date } Alert (showdate ( 28));
setInterval (function, milliseconds);
timer function set start function every few milliseconds,
setInterval (Show, 1000);
if the control timer button, click on the button will be repeated a plurality of times to start the timer, causing the return value id change
clearInterval (timer ID);
with the
acquired return value var id = Timer
innerHtml;
all content between the tags,
var oDiv = document.getElmentById ( "DIV1" ); oDiv.innerHtml = "<H3> I is the replacement text </ h3>";
Realization stopwatch
html body{margin: 0} #div1{height: 350px;width: 200px;background-color: #999;margin:100px auto;text-align: center} #count{height: 200px;width: 100%;background-color: #888;line-height: 200px;font-size: 40px;} #div1 input{display: block;margin: 5px auto;width: 80px;height: 40px;} span{background-color: #777;width: 40px;height: 20px;}
<div id="div1"> <div id="count"> <span id="h"></span> <span id="m"></span> <span id="s"></span> </div> <input id="start" type="button" value="开始"> <input id="pause" type="button" value="暂停"> <input id="stop" type="button" value="停止"> </div>
// function package, $ symbol enable function $ (ID) { return document.getElementById (ID); } // function package, so that when less than 10 seconds, the tens digit display of 0. The function SZ (COU) { IF (COU < 10 ) { return "0" + COU; } return COU; } the window.onload = function () { // start counting var cOUNT = 0; // set to a number, so that increased numbers of self- var Timer = null ; // set id a function call, clear id, call the function will not be repeated $ ( "S") the innerHTML. = "00" ; // second display tag so $ ( "m") the innerHTML. = "00" ;// let the label display division $ ( "H") the innerHTML. = "00" ; // let the label displays hours . $ ( "Start") onclick = function () {// clicks on the button to start the Timer = setInterval (function () {// Timing setting the calling function 1 sec COUNT ++; . $ ( "S") the innerHTML = SZ (COUNT % 60); . $ ( "m") the innerHTML = SZ (the parseInt (COUNT / 60)% 60); $ ( " H. ") the innerHTML = SZ (the parseInt (COUNT / 3600)% 24); }, 1000); } // pause $ (" pause ").onclick = function(){ clearInterval(timer); } // stop, all owned by data cleaning 0 $ ( "STOP") onclick. = Function () { clearInterval (the Timer); // call the function Clear, COUNT = 0; $ ( "S") the innerHTML. = "00" ; $ ( "m") the innerHTML. = "00" ; . $ ( "H") the innerHTML = "00" ; } }