[英]Use 'this' keyword while spreading an object
我有一個不尋常的問題。 我試圖實現的是在通過方法傳播時修改對象的屬性。 例子 現在,我希望 obj2 看起來像這樣: 但是由於這個范圍限定,只有 obj1 中的 prop1 被更改,而 obj2 看起來像這樣: 我知道之后我可以直接更改 obj1.prop1,但問題是代碼的第二部分(obj2 初始化 ...
[英]Use 'this' keyword while spreading an object
我有一個不尋常的問題。 我試圖實現的是在通過方法傳播時修改對象的屬性。 例子 現在,我希望 obj2 看起來像這樣: 但是由於這個范圍限定,只有 obj1 中的 prop1 被更改,而 obj2 看起來像這樣: 我知道之后我可以直接更改 obj1.prop1,但問題是代碼的第二部分(obj2 初始化 ...
[英]Adding event listeners to multiple input elements using plain JS (not jQuery)
我有一個在 jQuery 中完美運行的代碼塊,但它是我正在轉換為普通香草 Javascript 的項目的最后一部分,其特定目的是刪除對 jQuery 的任何和所有依賴項。 這是有問題的現有代碼塊: 如何僅使用普通的純 JS 實現相同的功能? 注意: inputComma 是一個自定義處理程序,它在用 ...
[英]Class Component ReactJS - setTimeout get wrong value in class component
應用組件: ProfilePageClass(問題出在這里): setTimeout 不顯示原來被關注的用戶對應的消息我認為這是 props 或 this 的問題,但我不確定。 誰能告訴我這是怎么回事? ...
[英]This keyword in an Inner Function not working (Javascript)
所以我試圖理解 javascript 中的this關鍵字和內部函數。 我有一個帶有this關鍵字的內部 function 但它returning "my hobby is undefined" 。 我怎樣才能讓它返回"my hobby is programming" 這是我嘗試過但沒有用的方法: ...
[英]Using $this keyword to add/remove class on onChange using jquery
在這里,我試圖在“.tt-select”select 更改時在此“.ingradient”class 元素中添加幾個類。 所以,我幾乎就在那里。 但是當我 select 選項時,有一個“.ingradient”項目列表。 我需要為我們當前選擇的那個特定的人執行以下代碼。 我知道我們可以使用 $th ...
[英]Decorator Typescript
為什么打字稿的 function 裝飾器不打印它裝飾方法的 class 的這個?interface IUserService { users: number; get(): void; } class UserService implements IUserService { ...
[英]RK1. what is the behavior of "this" key word in Anonymous inner class and lambda expression
**->**Anonymous inner class 這個關鍵字總是引用局部變量中當前的class。 **->**Lambda 表達式引用當前 class 實例變量而不是局部變量 ...
[英]Passing correct context with "this" to external method from class
假設我有一個非常簡單的 class 擴展了其他類,還有一個 object 的函數我傳遞給 class B ts 編譯器還說從runAction中調用時this上下文不正確有一個更好的方法嗎? 我們有超過 500 個操作,我們希望為每個操作提供對 class 數據的訪問,並且不想通過所有操作傳遞 a ...
[英]javascript function is not binding the 'this' when passed as a callback to the backend(node) using socket.io
我在前端的功能之一是使用“ this ”。 我這樣稱呼它: myFunction.call(objAsThis, param1, param2); 一切都按預期進行。 但是后來我嘗試使用socket.io將這個 function 作為回調傳遞給后端(node.js): 客戶socket.emit( ...
[英]I am trying to increase the count variable using this, but let is creating problem , whereas var works fine
我試圖了解“this”關鍵字的工作原理,並嘗試使用 function 增加計數變量。但是如果我使用 let 聲明計數,計數不會增加,但如果我使用 var 聲明計數,它就可以工作。 我不知道為什么會這樣。 ...
[英]TypeScript: extend "this" based on constructor parameters
我正在嘗試向 class 添加類型,它在構造函數中擴展了“this”。 我看到這個問題Typescript: extending "this" inside class但我事先不知道哪個 object 會傳遞給構造函數。 我試圖將作為 object 傳遞的字段識別為屬性。 ...
[英]How to bind a function to an object that is returned from a class method
標題的措辭可能很糟糕,但我不確定如何表達我想在這里做的事情。 基本上我所擁有的是一個包含兩種方法的類: 對象工廠類函數objFactory返回包含三個屬性(value1、value2、value3)的對象和綁定到該對象的另一個函數。 即myObj = {value1: 1, value2: 2, v ...
[英]Does super() run in compiletime and this() run in runtime? and why?
在此程序中,它將打印“Student 1 Person 1 Undergrad 2” 這意味着 super.method1() > super() of student this.method2() this of Undergrad() super() 是否在編譯時運行而 this() ...
[英]How to register this inside a function of a method?
如何在方法的這個函數中添加這個。 這是代碼 我正在嘗試將其放入 something 函數中。 我正在嘗試綁定此功能但未按預期工作。 好吧,箭頭功能工作正常,但我想知道發生了什么。 這是此代碼的實時版本 => https://playcode.io/1038919 我試圖在 javascrip ...
[英]How to properly use Laravel localization language-string as vue.js script data property
我在 vue.js 腳本(vue.js 組件腳本 2 片段)中有一個 sweetalert,它可以與兩個 Laravel 本地化語言字符串一起正常工作。 現在我試圖在另一個 vue.js 組件腳本中使用相同的語言字符串作為數據屬性。 問題:它不接受以下 sides.name 屬性。 vue.js ...
[英]Javascript - why is this referring to global window if I pass an arrow function as callback vs defined same func inside the callback handler?
為什么第一個例子中 this 的值是:this: myObject 和第二個例子中的 document/window? 如果這是在調用 function 時定義/評估的,那么我不明白。 ...
[英]How to automate the creation of "this." variables in Angular
在 Javascript 和更具體的 Angular 上工作,我經常使用this. 句法。 我想知道我是否可以連接變量以獲得this. 多變的。 例如,這是可行的嗎? 我的目標是自動創建this. 變量。 非常感謝您的幫助 ! ...
[英]toggling 3+ elements using OOP
請查看我的 Codepen(我在起點處留下了注釋): 我已經能夠以一種非常手動的方式實現我喜歡的東西。基本上,我希望徽章遵循與評論相同的行為,例如:- 已選擇送貨徽章 - 已激活 class 退貨徽章和調整徽章 - 刪除活動 class 選擇退貨后,交貨和調整會刪除活動 class 等(本質上是這種 ...
[英]Why the arrow function that returns arrow function inside componentWillUnmount lifecycle is not removed by removeEventListener? (React.js)
我目前正在研究 React.js Class 組件。 我在 componentDidMount 中使用 addEventListener 添加了監聽器,如下所示。 然而,問題就在這里。 卸載組件時,應該刪除 function。 然而,事實並非如此。 但是,當我像下面這樣更改copyBlock fu ...
[英]'this' is misbehaving (again) inside an ES6 method
剛剛開始使用 ES6 類。 據我了解,這應該在 class 內表現出可預測的行為,並且始終指向 object。但是,情況似乎並非如此: 在上面的代碼中,這僅指向構造函數中實例化的 object。 一旦調用 init() 方法, this指向 Window。為什么? 以及如何從內部方法訪問私有屬性? ...