Skip to content

關於要不要把 音韻地位 的對象方法都在構造時就 bind #30

@syimyuzya

Description

@syimyuzya

之前在 #29 裡提過一下,雖然沒採用,但放在這裡待討論。

#29 原本在 音韻地位.constructor 中加上了這樣的代碼(當時未考慮 constructor):

Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach(function (this: Record<string, CallableFunction>, key) {
  typeof this[key] === 'function' && (this[key] = this[key].bind(this));
}, this);

其作用是將 音韻地位屬於判斷 等方法在構造時立即 bind。

這樣會使這些方法的用法與 Python 相仿,但符不符合 JS 中對「對象方法」的期望行為呢?

(而且印象中除了 Python 外,別的語言(無論動態靜態)幾乎都沒有這種「隱式 bind」的用法(討論見此

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions