JS advanced — function is used as return value

Time:2020-10-16

Function is used as the return value

 

function f1() {
      console.log ("F1 function start");
      return function () {
        console.log ("function is used as return value");
      }
    }

 

Get the data type of the variable num
Determine whether the object is of a certain type
    var num = 10;
    console.log(typeof num); //num

    var obj = {};
    console.log(obj instanceof Object); //true

 

//In this case, the data type of the object [object object] is output
    console.log(Object.prototype.toString());
    //The data type of the output array [object array]
    console.log(Object.prototype.toString.call([]));

 

    var arr = [10, 20, 30];
    console.log(Object.prototype.toString.call(arr)); //[object Array]

    var arr = [10, 20, 30];
    console.log(Object.prototype.toString.call(arr)); // [object Array]
    console.log(Object.prototype.toString.call(new Date()));//[object Date]

 

//Determine whether the object and the type passed in are of the same type
function getFunc(type) {
      return function (obj) {
        return Object.prototype.toString.call(obj) === type;
      }
    }

 

    var ff = getFunc("[object Array]");
    var result = ff([10, 20, 30]);
    console.log(result); //true

    var ff1 = getFunc("[object Object]");
    var dt = new Date();
    var result1 = ff1(dt);
    console.log(result1); //false

 

Recommended Today

Web authentication and API using token

First of all, I’ll post the article I’ve read:1.http://www.cnblogs.com/xiekel…2.http://blog.leapoahead.com/20…3.http://blog.leapoahead.com/20…4.jwt demo :https://github.com/bigmeow/JWTFive https://github.com/jwtk/jjwt There are several good ones here, which are officially recommendedSix http://blog.csdn.net/koastal/… Anti replay attack scheme based on timestamp and nonce The company’s current web design is based on HTTP basic auth, and has always felt that there will be great security problems, and […]