JavaScript概览学习记录

JavaScript基础

  • 基础类型:number、boolean、string、null、undefined

  • 复杂类型:array、function、object

  • typeof
    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”

  • instanceof
    object instanceof constructor
    如果constructor.prototype.isPrototypeOf(object),则返回true

  • call&apply
    call和apply都可以改变this的值;
    call接受参数列表,apply接受参数数组。

    function a(b, c) {
    b == “first”;
    c == “second”;
    }

    a.call({a: “b”}, “first”, “second”);
    a.apply({a: “b”}, [“first”, “second”]);

  • try-catch
    使用throw抛出错误时,代码停止往下执行;
    可以使用try-catch对异常进行捕获,使代码可以继续执行下去。

  • 遍历object的keys
    for (var i in a) {
    if (a.hasOwnProperty(i)) {
    }
    }

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

  • 判断一个对象是数组
    Array.isArray();

  • 数组方法
    遍历数组
    [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”

  • bind
    function a() {
    this.hello == “world”;
    }

    var b = a.bind({ hello: “world”});
    b(); ==> true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值