tshet-uinh-js icon indicating copy to clipboard operation
tshet-uinh-js copied to clipboard

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

Open syimyuzya opened this issue 2 years ago • 2 comments

之前在 #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」的用法(討論見此

syimyuzya avatar May 05 '22 05:05 syimyuzya

其實這樣寫只是要回避 TS 的型別檢查,實際上是不應該這麼寫的🙈

graphemecluster avatar May 06 '22 04:05 graphemecluster

其實這樣寫只是要回避 TS 的型別檢查,實際上是不應該這麼寫的see_no_evil

咦 TS 是會給它報什麼樣的問題呀?

syimyuzya avatar May 06 '22 04:05 syimyuzya