• 请不要在回答技术问题时复制粘贴 AI 生成的内容
banxi1988
V2EX  ›  程序员

类与 this:从 C++ 到 JavaScript

  •  
  •   banxi1988 ·
    banxi1988 · Jun 3, 2018 · 2028 views
    This topic created in 2946 days ago, the information mentioned may be changed or developed.

    摘要:

    1. C with Classes 中 this 作为语法糖的作用。
    2. GoPython 中的 thisself
    3. JavaScript 中的 this
    • this 运行期绑定特性
    • this 会漂移吗?
    • 为什么我们需要 bind 函数。
    • 箭头函数中的 this

    原文链接

    2 replies    2018-06-03 23:41:06 +08:00
    kimown
        1
    kimown  
       Jun 3, 2018 via Android
    纯思考,楼主,你认为 js 的 this 设计的好吗,如果让你来设计,会和现在 js 一样吗
    banxi1988
        2
    banxi1988  
    OP
       Jun 3, 2018   ❤️ 1
    @kimown 我思考了一下。
    其他动态语言中 `this` 这个的指向问题没有像 `JS` 里面这么复杂。就比如说 `Python` 很多时候我们都不会花时间去思考这个 `this` 指向的是什么? 这从方面上讲,这个`this` 增加了使用者很大的心智负担。
    如果我来设计的话,我会让 js 中的函数默认`bind` 对当前最近的 `this` 对象。 这样使用者在基本使用的时候就不会需要有这些思考。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2798 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 04:25 · PVG 12:25 · LAX 21:25 · JFK 00:25
    ♥ Do have faith in what you're doing.