JavaScript scattered knowledge points

array

Array method:

var arr = [1, 2, 3 ];
arr.push( 4); // arr='[1, 2, 3, 4]' add one or more elements to the end 
arr.pop(); // delete the last element 
var b=arr.push(12 ); // b=[1, 2, 3, 12] push arr first 
var c=arr.pop(); // c=12 first pop 
arr.concat() // Connect two or more arrays 
sort() // sort array elements 
arr.reverse() // reverse arr=[3, 2, 1]

 

function

function foo(a,b){ return a+b} // function declaration 
var foo= function (){} // function expression assignment 
var foo= new Function('a','b','return a+b '); // Constructor, the last parameter is regarded as the function body dynamic creation function

call、apply

function foo(c, d) {
        console.log(this.a + '+' + this.b + '+' + c + '+' + d)
    }
    var obj = {
        a: 1,
        b: 2
    }
    foo.call(obj,3,4);
    foo.apply(obj,[3,4]);

 

jQuery

Operates on the class of an element

$('p').removeClass() // delete 
$( 'p').toggleClass() // toggle switch property set true to add, false to remove; if you don't write the class name, all 
$( 'p').addClass () // Increase 
$( 'p').deleteClass() // There is no such method

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325162888&siteId=291194637