JavaScript basic 6

Timer

setInterval () function call to the specified period in milliseconds or calculation expression

Syntax setInterval (code, millisec [, "lang"])    

code to call a function or code string to be executed.

The time between the periodic execution or calling code millisec interval, in milliseconds.

return value 

Can be passed to a window.clearInterval () so as to cancel the value of the code is executed periodically.

setTimeout () setTimeout (code, millisec) to call a function or an expression after a specified event equivalent to the countdown starts

clearinterval () to cancel the setInterval () event set  

   /**
         * setInterval(function(){},time),
         * 
        * / 
        Each box = document.getElementById ( 'box' );
        was BTN = document.getElementById ( 'BTN' );


        was setNumIndex = setInterval ( function () {
             was con = Number (box.innerHTML);
            box.innerHTML = con + 1;
        }, 200);

        was flag = true ;
        btn.onclick = function () {
            if (flag) {
                clear interval (setNumIndex);
            } else {
                setNumIndex = setInterval(function () {
                    var con = Number(box.innerHTML);
                    box.innerHTML = con + 1;
                }, 200);
            }

            flag = !flag;
        }

function

Or execution of event-driven code blocks can be reused when invoked

function function name (parameter list) {
          Function body
           return value;
      }
 Function call:
       Function name (parameter values);
ele.onclick=function(){
      
     }
    1. There parameters, return value
     2. parameters and returns no value
     3. no parameters and returns no value
     4. no parameters, return value
     5 anonymous function
Variable Scope
Local variables in the variable declared inside a function can not be accessed outside the function
Global variables in the variable declared outside a function, inside the function can access
Variable lift
We will declare the language itself in the first half of the back of the variables are automatically promoted to the beginning of the function
Type of assignment
Value assignment
var  a='hello how are you'
var b = a; b = a copy of a copy corresponding to a change will not change the contents of b
Assignment by reference
where, R1 = [1,2,3];
var arr2 = arr1; a direct reference to a change in the content will change with   
 At present, only the array is a reference type assignment
 

Guess you like

Origin www.cnblogs.com/leroywang/p/12037447.html