[英]How to use constructors as a prototype chain?
假設我有一個 javascript 構造函數: Person “類型”有一個方便的方法, hello ,我想在另一種類型Student上重復使用。 我希望Student具有以下結構: 一種選擇是按原樣使用Student的代碼。 由於通常的原因,這是次優的,例如,如果我希望它鏡像Person類型, ...
[英]How to use constructors as a prototype chain?
假設我有一個 javascript 構造函數: Person “類型”有一個方便的方法, hello ,我想在另一種類型Student上重復使用。 我希望Student具有以下結構: 一種選擇是按原樣使用Student的代碼。 由於通常的原因,這是次優的,例如,如果我希望它鏡像Person類型, ...
[英]Error with decorator in Typescript: Unable to resolve signature of property decorator when called as an expression.ts(1240)
嘗試在 typescript 上創建一個簡單的裝飾器 function 時遇到問題。我不知道發生了什么。 這是裝飾器: 當我像這樣在另一個文件上調用它時 我收到以下錯誤: 當作為表達式調用時無法解析屬性裝飾器的簽名.ts(1240) 如果我不強制裝飾器的返回類型為任何類型,我會得到上一個錯誤以及這 ...
[英]Possible way of overloading functions or prototypes with different return data types RPGLE
我有一個根據輸入參數返回 char/packed/date 數據類型的過程。 我正在考慮使用重載的可能方法,但 IBM 不允許重載返回不同類型變量的原型。 我解決的一種方法是返回一個包含所有 3 種數據類型的數據結構,從 position 1 開始,然后只選擇我需要的一個。 所以代碼看起來像這樣。 ...
[英]Create a Spring Bean programmatically, but with Autowired within it
如何實例化其中包含一些@Autowired bean 的 Spring Bean? 需要注意的是,實例 bean 類型必須在運行時動態發現(而@Autowired bean 仍然可以是單例)。 例子: 界面 ClientA.class 客戶端B.class ClientFactory.clas ...
[英]How do I add a string to an array of a constructor created object it was called on?
聲明一個 function Dog,它在使用 new 關鍵字調用時創建一個 Dog object 的新實例。 每個 Dog object 都應該有一個 name 屬性和一個 breed 屬性,這兩個字符串在調用 Dog function 時作為 arguments 傳入。它還應該有一個名為 tri ...
[英]What is the difference between the Momento and Prototype Design Pattern?
Momento 和原型設計模式(來自 GOF)之間觀察到的差異: Momento 設計模式使用 class x 來創建 class y 的內部 state 的快照。 原型設計模式使用 class y 創建 class y 的內部 state 的快照(=克隆)。 Momento 設計模式是一種 ...
[英]Inject a function/property to another function/object that can be called or read/set from functions within that function?
我可以在 JavaScript 中添加一個 function 到已經存在的 function 或 object 中的 function 然后“突然”可以“看到”並調用自己嗎? 下面是一個例子來演示: 所以createThing()中顯然不存在theFunction()。 有沒有什么辦法可以在外面添 ...
[英]Javascript: creating a class equivalent to new Image()
如何創建 class 之類的new Image() ? 例子: 我向這個 class 添加了一個原型,例如: Image.prototype.convert = function() {} 而且我仍然可以執行 img.convert(); 所以我像這樣創建了一個 class: 這樣我將無法訪問 n ...
[英]Is there any String Prototype for Setters in JavasScript?
在 JavaScript 中, valueOf方法用於獲取字符串的原始值。 是否有任何方法用於設置字符串的原始值。 ...
[英]Adding multiple eventListeners using HTMLElement.prototype is not working
我擴展了HTMLElement原型以添加多個eventListener 。 我的方法declare global { HTMLElement { addEventListeners(): any // with a 's' } } type CallBackFunction< ...
[英]Javascript: is there "Symbol.iterator" analogue for the object spread syntax - { ...obj }?
有一個眾所周知的符號: Symbol.iterator ,當定義為 object 上的生成器 function 屬性時,允許 object 在[...object]語法中使用。 所以,你可以這樣做,例如: 但是,我找不到該功能的類似物,允許這樣做: 或Object.assign非自有財產。 恰當的 ...
[英]Mdn Docs __proto__ vs __proto__ Accessor
在 mdn 的原型鏈文檔中,它指出所有對象都繼承Object.prototype.__proto__ setter,它可用於設置現有 object 的 [[Prototype]](如果對象上的__proto__鍵未被覆蓋)。 然后它繼續說 Object.prototype.__proto__訪問器是 ...
[英]JavaScript Printing Twice
function Person() { throw new Error("The person is abstract constructor function"); } Person.prototype.personName = "John"; Person.prototype.age = 21 ...
[英]Add setStragy to VectorSource
我使用 openlayers js 庫版本 6.15.1 我有一個繼承 VectorSource 的類。 我不知道在我的構造函數中做什么因為我想要我自己的策略。 我不能調用 super({ strategy: this._myStrategy, ... }) 那么該怎么做呢? 我可以在 Vecto ...
[英]Prototypes on Custom Elements
假設我有一個帶有屬性tableVal="10"的自定義 HTML 元素標記<custom-table> 。 我想在不使用.getAttribute()的情況下輕松獲取tableVal (因為我正在創建一個易於使用的公共 API) 。 這是我正在嘗試做的事情: 輸出: undefined ...
[英]I wanted to solve a pixel problem on my figma I need
當我移動東西時,無論是矩形,文本還是其他東西都是十進制數,它們不會逐像素移動,我想要一種方法來解決這個問題,因為昨天它仍然正常我試圖移動物體和其他物體,但它們是十進制數,我希望它們在之前而不是十進制數中逐像素移動 ...
[英]regex as protobuf message field name?
我們可以在 protobuf 字段名稱中定義正則表達式嗎? 我將請求作為 client.py 文件中的字典列表發送"cur_cur_bin": [{"cur_cur_bin1_bin3_bin1": 4,"cur_cur_bin3_bin5_bin8": 6} ] 我定義了 .proto 文件, ...
[英]Using .map() over a Map<K, V>() in TypeScript
我想在我的 react TypeScript 應用程序中擴展 TypeScript Map類型,以允許我使用.map() ,就像您使用Array一樣。 我發現這篇文章描述了幾種方法,但對我來說最自然的 TypeScript 是Jeremy Lachkar的回答,盡管它不是很受歡迎。 這意味着我不必 ...
[英]Typescript add static method to a method
我定義了一個包裝 fetch 的方法,以便自動處理某些邊緣情況並提供統一響應 class 警報系統。 我不想自動將響應解析為 json(該平台不僅會請求 JSON)並想出了添加到獲取方法的原型 a.json 調用以自動解析和強制 promise 的想法,但發現我調用 integratedFetch. ...
[英]Can anyone help me to undrstnd the output of the below code
在這里,我試圖檢查proto是如何工作的。 為什么我不能訪問 obj1. 原型.getName ...