推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
cz6uiw

关于 js 判断对象接口是否存在的问题

  •  
  •   cz6uiw · Dec 6, 2016 · 2779 views
    This topic created in 3622 days ago, the information mentioned may be changed or developed.

    突然想到一个问题,在想是否有比较优雅的写法,或者什么工具支持: 就是当我们去使用的一个 js 对象的时候,不考虑前面的层层逻辑,单单我要执行 data 下面的 callbackFn 方法,伪了防止 npe 的情况,那么我可能要这么写

    data && 'function' == typeof data.callbackFn && data.callbackFn();

    有没有比这种感觉看起来更好的写法的?

    3 replies  •  2021-01-14 10:41:56 +08:00
    cz6uiw
    cz6uiw
    OP
    Dec 6, 2016
    1
    打错,应该是节点
    mukti
    mukti
    Jan 5, 2021 via iPhone
    2
    时隔几年,现在有了,链判断。哈哈哈
    cz6uiw
    cz6uiw
    OP
    Jan 14, 2021
    3
    @mukti 哈哈哈
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2251 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 11:21 · PVG 19:21 · LAX 03:21 · JFK 06:21
    ♥ Do have faith in what you're doing.