了不起的Node.js

JavaScript概览

2018-01-10  本文已影响12人  好吃的野菜
   typeof 0 ==> "number"
   typeof false ==> "boolean"
   typeof "" ==> "string"
   typeof null ==> "object"
   typeof undefined ==> "undefined"
   typeof [] ==> "object"
   typeof function(){} ==> "function"
   typeof {} ==> "object"
   
   typeof new Number(0) ==> "object"
   typeof new Boolean(false) ==> "object"
   typeof new String("") ==> "object"
   typeof new Array() ==> "object"
   typeof new Function() ==> "function"
   typeof new Object() ==> "object"
   function a(b, c) {
       b == "first";
       c == "second";
   }
   
   a.call({a: "b"}, "first", "second");
   a.apply({a: "b"}, ["first", "second"]);
 for (var i in a) {
       if (a.hasOwnProperty(i)) {
       }
   }

或者在V8引擎中:
Object.keys(a);

遍历数组

   [1, 2, 3].forEach(function (v) {
       console.log(v);
   });

过滤数组

   [1, 2, 3].filter(function (v) {
       return v < 3;
   }); ==> [1, 2]

改变数组

   [1, 2, 3].map(function (v) {
       return v * 2;
   }); ==> [2, 4, 6]

移除空格
" hello ".trim(); ==> "hello"

    function a() {
        this.hello == "world";
    }
    
    var b = a.bind({ hello: "world"});
    b();  ==> true
上一篇 下一篇

猜你喜欢

热点阅读