zoukankan      html  css  js  c++  java
  • On jQuery

    http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/

    /*******************

    The short version is: a function invocation like fn(...args) is the same as fn.call(window [ES5-strict: undefined], ...args).

    Note that this is also true about functions declared inline: (function() {})() is the same as (function() {}).call(window [ES5-strict: undefined).

    **********************/

    Because jQuery makes such heavy use of anonymous callback functions, it uses the call method internally to set the this value of those callbacks to a more useful value. For instance, instead of receiving window as this in all event handlers (as you would without special intervention), jQuery invokes call on the callback with the element that set up the event handler as its first parameter.

    This is extremely useful, because the default value of this in anonymous callbacks is not particularly useful, but it can give beginners to JavaScript the impression that this is, in general a strange, often mutated concept that is hard to reason about.

    If you understand the basic rules for converting a sugary function call into a desugared func.call(thisValue, ...args), you should be able to navigate the not so treacherous waters of the JavaScript this value.

    this-table.png

  • 相关阅读:
    NDK开发,如何配置 debug环境
    NDK 开发中,各种指令集的坑,arm64
    levmar ndk 编译
    kubernetes 存储
    kubernetes 存储
    Docker 仓库
    docker 容器
    查看系统日志
    linux 进程命令小结
    DaemonSet
  • 原文地址:https://www.cnblogs.com/zjsct/p/3598669.html
Copyright © 2011-2022 走看看