Questions tagged [this]
In many object-oriented languages, "this" is a reference to the current instance of the class or object. Use with a language tag, like [javascript], [java], [c#], etc.
6,310
questions
0
votes
0
answers
40
views
Use this keyword in static method of class
export default class SpecialtyAPI {
public static async getSpecialtyList(request: Request, response: Response): Promise<TResponseData> {
public static async getSpecialtyData(request: ...
1
vote
3
answers
162
views
How to create a fluent chaining equation solver that can work `one().plus().two().equalTo()`
I have been given a task at my internship , I have to create math operations like plus(), minus() etc. using this and new keywords.
example: one().plus().two().equalTo() , given line of code must ...
0
votes
1
answer
46
views
What is VB.net equivalent of this in inherited BaseCollection class?
I try to convert following C# code to VB.NET but I block on following code
public class StringCollection : CollectionBase
{
public String this[int Index]
{
get
{
...
0
votes
0
answers
31
views
Regular function in a function is modifying the outer this context [duplicate]
Please look at the code below.
I think the arrow functions do not have their own this. so they take context from wherever they are called but regular functions should have their own this (that is the ...
0
votes
1
answer
27
views
I need "multiple scopes" inside a event listener method in a class ("this" scope) JavaScript drag and drop API
(Im new to JS)
Im coding a web app that consist in a 4x4 table with numeric pieces from 1 to 15 and an empty space.
I was messing with the drag&drop API, then I noticed that my methods for the ...
-1
votes
0
answers
31
views
"this" is undefined in an array of functions [duplicate]
When I run the example in Firefox the correct function is executed from the array of functions. However in the f0 function this is undefined. Functions are first class in JS, so having a function in ...
-2
votes
0
answers
73
views
Why saving the `this` pointer in another pointer and using it for method chaining doesn't work? [duplicate]
Why in this MWE the operator+ method doesn't work if the operator+= method does return *self but works if it does return *this ?
MWE :
#include <iostream>
class Class
{
int value;
Class*...
0
votes
1
answer
38
views
reactjs- A custom function that passed as a prop into an component that inside of map function doesn't work
I am doing a to-do app but with Class Components in React because I wanted to learn logic of state before Hooks.
I have only one index.js file so it's not that complicated.
These are my packages:
var ...
0
votes
2
answers
38
views
How to assign different audio to different buttons after clicked event
<h1 id="title">Drum 🥁 Kit</h1>
<div class="set">
<button class="w drum">w</button>
<button class="a drum">a</...
-1
votes
1
answer
54
views
Execution context for object literals and object literal methods
var objLiteral = {
name: 'Kumar'
myNameIs: function() {
return this.name;
}
};
objLiteral.name = 'Arvind';
objLiteral.myNameIs(); // returns Arvind
Can someone explain how the ...
0
votes
0
answers
41
views
Mixed results with is_page() WordPress function, when using either $this, or self
I'm trying to understand something. I inherited an old Wordpress plugin, and I'm chewing my way through converting it from PHP5 -> PHP8.
I came across this check, which caused an error when ...
-1
votes
1
answer
44
views
How can I solve 'this'? [closed]
target = 'global honey';
const test = () => {
console.log(this.target); // global honey
}
const object = {
target: 'local honey',
action: test
}
object.action();
The output ...
0
votes
1
answer
25
views
Vue3 cannot obtain instance of component from another component [closed]
Vue 3 Composition API
I have two components A and B
I use the mode script setup
I don't know how to call a function declared in component A into the component B. Please help me.
I want to get the this ...
0
votes
0
answers
40
views
How to make a JavaScript class constructor for an HTML element
I have a function element() that I use to create new elements.
function element(name, className, attributes, innerText) {
function element(name, className, attributes, innerText) {
const element =...
0
votes
1
answer
39
views
How can i get the content of a specific div sharing the same class with other div ? i get an empty string with 'this'
What i tried :
const adressLine = $('.adressLine');
adressLine.on('click',()=>{
console.log('button cliked');
var text = adressLine.text();
console.log(text);
});
...
2
votes
1
answer
102
views
What will be the value of 'this' for a function in an array in an object?
What will be the value of this for the function in the methodArray array, which is a property of myObject? Also, is methodArray[0] a normal function or a method?
let myObject = {
property: "...
1
vote
1
answer
74
views
Customize fullCalendar js 'show more' link behaviour
I'm integrating fullCalendar V6.1.8 ( https://fullcalendar.io/ ) into my app. in the 'dayGrid' view i want to customize the behaviour of 'show more' button ( which opens a modal by default)
function ...
0
votes
1
answer
41
views
Javascript 'this' to pass a canvas to function when Page is loaded
I'm trying to pass the HTML canvas element as a parameter to a function, and I thought using the 'this' keyword would work, but I'm having trouble with it. Can someone please assist me in using the '...
0
votes
1
answer
96
views
This-pointer and linked list
Stroustrup writes in "Design and Evolution of C++":
Without this or some equivalent mechanism, member functions cannot be used for linked list manipulation.
What does he mean by that and ...
1
vote
0
answers
48
views
implicitly has type 'any' because it does not have a type annotation
I have this function:
and I'm receiving this error message from Typescript: 'this' implicitly has type 'any' because it does not have a type annotation.
Here's the function in text:
async function ...
0
votes
2
answers
72
views
What's the this value in callback arrow functions? [duplicate]
So as I am reading on the execution context in javascript and how does it works, everything seemed fine until I tried some examples on the this value of callback arrow functions.
const printCard = ...
0
votes
1
answer
49
views
How to target this button in the if condition in vanilla javascript
I have several buttons with the same class that toggle dropdown lists, the lists are closed if the user clicks somewhere outside the button, but if the user clicks on the other button with the same ...
0
votes
0
answers
19
views
My question is why font-awesome icon was not working properly
This is font-awesome icon
hi there give me the solution of this problem, why font-awesome icon was destroy every time and how to solve this problem so please give me the solution thank you so much .
I ...
-3
votes
1
answer
27
views
How to keep function context when given as a parameter [duplicate]
When copying a this.xxx function, it seems that some kind of context is lost.
In the following example, the call to this.post works fine, but the postCopy leads to an error.
class MyClass {
...
1
vote
2
answers
82
views
Access VBA: Me Keyword in Public Procedure's Optional Argument Default Value?
Can one use the Me keyword in defining the default value of an optional argument to a public procedure, in VBA? An hour or two of Googling around yields no guidance.
Several parameter / search forms ...
0
votes
0
answers
10
views
this keyword is outputing different outputs in same object why? [duplicate]
i learned that this keyword inside an object method this refers to the object it self but when it tried it not why,
when i tried that in arrow function syntax this keyword referred to the object it ...
6
votes
3
answers
143
views
Why can't we capture this in a lambda that is the default parameter of a method?
I'm attempting to capture the this pointer within a lambda function that serves as the default parameter for a method.
My goal is to invoke a method of this class from within the lambda, which ...
0
votes
0
answers
14
views
why these 'this' keywords are referring to different objects [duplicate]
const person = {
name: "aman",
age: 19,
hello: [2,123,13,1,23],
showDetails(){
this.hello.forEach(function(items){
console.log(this) // referring to ...
0
votes
1
answer
18
views
Active class for single class element jQuery
I have these buttons which are actually p elements in a grid and they all have the same class. I would like to change the color of the p element which the user clicks on. How can I add an active class ...
0
votes
0
answers
31
views
What is the difference between this two approaches ? Why one approach works while the other doesn't?
class A {
A(int value){
print(value);
}
}
class B extends A{
int x;
B.one(this.x) : super(x);
B.two(int x) : this.x = x, super(this.x);
}
We have here a class called "B" ...
1
vote
2
answers
601
views
How to solve warning 'Use of $this in global code might be unatendedPHP(PHP0437)' when layouting view in Codeigniter 4?
I'm still beginner in codeigniter. I try to layouting template (dinamic page) with view layout in codeigniter 4. But all of code
$this
have warning that says
Use of $this in global code might be ...
0
votes
1
answer
55
views
How context bind on click in vue?
How context bind on click in vue?
Html with click function:
<li v-on:click="itemClick($event, this)"></li>
My vue js code:
var app = new Vue({
el: '#mainApp',
methods: {
...
0
votes
0
answers
7
views
jquery get list of input values after blur one
I have a plugin translate page:
In this page I insert a row of flags and a form with original text of post and inputs for translation.
At the end of form there is the submit button.
I want to activate/...
-1
votes
1
answer
24
views
jquery - add/remove class of just one input field, not all of them using $(this)
So now I have it change the BG color, but on every field with that class name.
How do I correctly add to the class to just the one being checked by the onchange click and not all that have the same ...
0
votes
2
answers
99
views
In C++, is a free function taking a struct as an argument faster than a class with a member function to do the same thing?
I am alluding to Klaus Iglberger's timeless lecture here. I have a (relatively) simple function that takes a single float as input and returns the result as another float. The function needs a ...
0
votes
0
answers
18
views
How is the keyword "this" referenced in an anonymous function vs a fat arrow function? [duplicate]
I am not understanding how the this keyword is referenced when used inside or invoking certain functions. I've provided a code snippet to illustrate my misconceptions.
//I am not understanding ...
0
votes
0
answers
21
views
Access global this in Arrow function [duplicate]
I have two functions. One is normal function and one is arrow function inside an object.
Inside the arrow function I want to access the inner Name and global name.
const name = "globalname";
const ...
0
votes
0
answers
46
views
How to Emit an Event from TinyMCE Component to Parent?
I'm using Vue 2.0. TinyMCE version:
"tinymce": "^6.6.2",
"@tinymce/tinymce-vue": "^3.2.8"
I have created a custom component which is a tinyMCE text editor. It ...
1
vote
1
answer
44
views
Passing "this" as a parameter vuejs 2
Im trying to pass a vuejs object (Object A) as a parameter (into Object B) so that I can access all the methods and variables without passing them all separately as params.
So it looks like this:
<!...
1
vote
2
answers
83
views
this constructor citation not working in java
I tried to apply the this() method for calling the same constructor in java for trying to make a constructor wehere just vy providing the name and the class it would select the parameters of the ...
1
vote
0
answers
29
views
different this behavior in arrow functions for object and classes [duplicate]
I'm analyzing the behavior of this in classes and object and have one question which doesn't give me peace. I have this code-snippet:
const obj = {
a: 5,
say: () => console.log(this.a)
}
obj....
-2
votes
3
answers
107
views
JavaScript Object Literal - how to replace `this` keyword for another thing
Is there any way to avoid the constant use of the this keyword to access the properties and methods of the current object?
I tried something like in Example 2, but it doesn't work at all.
Example 1:
&...
0
votes
0
answers
48
views
`ThisType` does not affect the `this` in the method inside a wrapper
I want to access this.data.a in the code below, and the compiler can infer the type of this.data.a as number as expected.
function defineComponent<T, U>(
options: {
data: T;
methods: U;...
0
votes
3
answers
37
views
I am just trying to run a function inside an object but it returns undefined output [closed]
const rajat = {
FirstName: "Rajat",
middleName: "Kumar",
lastName: "sahoo",
birthYear: 1998,
location: "Bhubaneswar",
job: "Programmer",
friends: ["Michel", "Jack", "James", "Juile"],
...
0
votes
1
answer
35
views
Arrow function this behaviour [duplicate]
Example 1
const obj = {
perimeter: () => {
console.log(this); // this points to window
}
}
obj.perimeter()
const obj = {
sing(){
console.log(this);
const b = () =>{
...
0
votes
0
answers
15
views
Display div element onclick of the selected button over table data on a JSON array objects after it's rendered in React JS
I have a JSON object like this:
import React, {useState}from 'react'
export const SitePrefData1 = [
{"groupid":"SFRA Unified Feature Cartridge","description":"...
0
votes
1
answer
33
views
Trying to understand effect of binding the call function
I came across following (cleaned up) code and trying to understand what exactly is going on. I'm generally aware that bind function accepts this paramete, first parameter acts as argument etc. Also ...
0
votes
1
answer
20
views
"'ChildInheritedClass' does not contain a constructor that takes 1 arguments"
I am getting these 2 compiler errors :-
"There is no argument given that corresponds to the required parameter 'mark' of 'ParentClass.ParentClass(int)."
"'ChildInheritedClass' does not ...
-2
votes
2
answers
90
views
Can't call constructor of inner class in a static context -- "non-static variable this cannot be referenced from a static context" [duplicate]
I have an OuterClass and an NestedClass. Like this.
public class OuterClass
{
public class NestedClass
{
}
}
Whenever I try to call the constructor of NestedClass in a ...
4
votes
0
answers
52
views
Object pointer (this) saved in the constructor for later use seems to have incorrect value [duplicate]
I came across a strange bug today, which basically boils down to the following minimal example:
#include <cassert>
struct S* ps;
struct S{
S(){
ps = this;
}
//~S(){} //(*)
}...