Questions tagged [this]
Keyword that refers to the current class instance or object in many object-oriented programming languages.
6,073
questions
1
vote
1
answer
22
views
How can I change data element on Vue.js?
<div id="SearchAddress">
<div class="main_class">
<div class="find_juso_map">
<input type="button" v-on:click="...
0
votes
1
answer
20
views
easily get text appended to a node on d3 graph
I can't get my head around the d variable conventionnally used in d3.
Once the graph is generated, i'd like to pass the text value as a variable on click (or at least log it on console).
const ...
0
votes
0
answers
29
views
why "this" keyword in arrow function represents the object rather than global object(window) [duplicate]
I am learning the behavior of this keyword in ES6 class , before I have learnt that this keyword in object functions, represent the following :
In regular function, this represents the the current ...
-2
votes
3
answers
74
views
how does the 'this' pointer work in inheritance in c++?
questions:
in the code below, the 'this' pointer points to different things in base and derived classes, even though it technically contains the same address. why is that.
what is happening when the '...
0
votes
0
answers
10
views
JavaScript: this keyword not working inside of object? [duplicate]
I have this object "names" which holds an array of names, a function to add a name to the array and to make an unordered list of the array. I would expect that "this.names" would ...
-1
votes
0
answers
19
views
Javascript THIS keyword problem usage in a function [duplicate]
Thank you for reading this.
I ran into some errors running my program. What I'm doing is instantiating an object of the constructor function "Stapel", then using that object ('newstapel') to ...
0
votes
0
answers
26
views
C++ SigSegv from multimap read using shared_ptr, this and Polymorphism
So, I'm trying to code a scheduler for tasks.
My scheduler is using a multimap like follows:
typedef std::shared_ptr<Task> TaskPtr;
typedef std::pair <long, TaskPtr> Task_Pair;
[...]
std::...
0
votes
2
answers
33
views
how to get parent object property in foreach function
for example
I can't reach 'this.ret' so use 'obj.ret' in loop.
is this right way?
const obj = {
ret : 0,
sum : function(arr){
$.each(arr, function(i, v){
obj.ret += v //Can't reach ...
0
votes
5
answers
54
views
I don't know why this 'this' method doesn't work?
const list = {
name: 'Harry Potter',
birthYear: 1995,
calcAge: function () {
this.age = 2002 - this.birthYear;
return this.age;
}
};
console.log(list.age);
0
votes
1
answer
33
views
How to use this keyword inside eval in javascript?
Having this:
const person = {
name: "James Smith",
hello: function (x) {
console.log(this.name + " says hello " + x);
}
}
function newContext() {
this.name = "...
0
votes
1
answer
49
views
Java, get calling instance [duplicate]
Following example
public class C{
A myA;
public C(){
myA = new A();
}
}
public class A{
C myOrigin;
public A(){
// How to set myOrigin to the instance
...
1
vote
0
answers
42
views
How to modify object value stored in a literal through this context in Vue or JavaScript?
I am in Vue.js and trying to correct inappropriate quantity input value like "12jd". They belong to item objects which are in a array literal called store (which is defined in data( ) return)...
0
votes
0
answers
25
views
bind `this` to a method passed into a class [duplicate]
I need to create a class, but later add a method to the class, and that method needs access to properties of the class. I've tried binding this, but it is undefined when the method runs.
class ...
0
votes
0
answers
29
views
Binding 'this' in javascript function [duplicate]
I have a function:
interval(duration, fn) {
var _this = this
this.baseline = undefined
this.run = function(){
if(_this.baseline === undefined){
_this.baseline = new Date().getTime()...
-1
votes
0
answers
21
views
Call one constructor from other [duplicate]
I`ve written constructor and want to implement another one with default parameters,
But get
Error CS0149 Method name expected
How can it be solved? calling anther constructor by thisshould ...
-1
votes
2
answers
69
views
javascript function scope accessing "this" [duplicate]
I have the following sample code. I'm trying to get the this.key inside the namespace function but it's always returning undefined despite me changing the function call, or using arrow approach etc.
...
0
votes
0
answers
20
views
Why arrow function has different parent-scope in this two scenarios? [duplicate]
I know arrow functions binds the parent-scope to 'this' keyword, but is it not the same parent calling the arrow function in this two scenarios?
Both are being called by a console.log inside a "...
1
vote
0
answers
89
views
C++ why is `this` necessary? [duplicate]
With GCC, we can't access the member in the base class without writing this explicitly, but it works on MSVC, what is going on? Is it because of the CRTP?
#include <iostream>
template<class ...
0
votes
0
answers
17
views
Why do we bind "this" to a method in a react component [duplicate]
Can you explain in simple terms why we bind "this" to a method in a react component? To the best of my understanding, when it's called, it loses its connection that specific component it's a ...
2
votes
2
answers
87
views
What's the shortest way to bind variable $this to a callable object field?
I bound the $this variable with Closure::bind() method (lines 12-13) to my getName() and getAge() methods (lines 4 and 7) so that they can refer to their own member fields (lines 2-3) in an instance ...
0
votes
0
answers
21
views
Inner function not printing this value? [duplicate]
Want to see why printName() function console.log not printing the value? What is the value this holds?
const person = {
firstname: 'John',
lastname: 'Muir',
name: 'hello',
fullname() {
...
0
votes
1
answer
98
views
Is this pointer always a runtime construct
I am learning about the this pointer in C++. And i came across the following statement from the standard:
An expression e is a core constant expression unless the evaluation of e, following the rules ...
1
vote
1
answer
24
views
Showing class property value on click
I need to display the this.name in the console when clicking the button element.
I could replace inside clicked() and set console.log(myBtn.name) but I'd like this method to work with any object.
Is ...
0
votes
0
answers
12
views
Nested functions not affecting objects in bidimensional array declared within global scope
I have a bidimensional array filled with Cell objects.
How can I do to make addToGrid(asset); (and nested functions) use the context of each Cell to set cells so that I can use it in draw method ?
...
-2
votes
0
answers
44
views
How does this keyword work with recursion
I'm trying to understand how does the second piece of code seems to have problems
public Boolean Search(int n,Main Node){
if(Node == null) return this.rs;
else{
if(Node.data == n) {
...
-1
votes
2
answers
32
views
How does referring to class name through 'this' keyword while calling another constructor from a constructor set values to an object? [closed]
When calling a constructor from a constructor, we use the 'this' keyword. The 'this' keyword refers to the class name. Then how are the values set in the object when we are only referring to the class ...
1
vote
4
answers
57
views
How to avoid calling this.field for every field in a java class
Is there a way to avoid calling this.field for every field in a class ?
public class Test {
private String name;
private String email;
public Test(String name, String email) {
// ...
-1
votes
1
answer
60
views
Understanding extend and method overwriting
This is a follow-up question from the previous: Why is the parent prototype method still executable after overriding?.
As we see, the literal object {metadata, aaa, init} was initialized by the extend ...
1
vote
0
answers
98
views
Contradiction about this parameter in the C++ standard
I am learning about classes in C++. In particular, i came to know that this is a prvalue expression inside a non-static member function.
From class.this#1:
In the body of a non-static member function,...
0
votes
0
answers
22
views
Why can't my JavaScript Class's method call a neighbouring method? [duplicate]
It seems the buildGeoLocation() method cannot run this.requestHandler() but I can't seem to work out why.
The console shows Uncaught TypeError: this.requestHandler is not a function.
Below is my code:
...
2
votes
2
answers
97
views
Is there no such thing as "implicit this parameter" in the Standard?
Recently, I asked this question where one of the answers says:
There's no such thing as "implicit this parameter" in the standard. The standard calls it an "implicit object parameter&...
0
votes
1
answer
46
views
How to use IntersectionObserver inside class? [duplicate]
Encountered a problem with using IntersectionObserver inside a class. For example, I am creating from my class constructor observer instance and create a callback - function in the current class. When ...
0
votes
0
answers
14
views
Why I cannot acces class properties when passing callback to setTimeout without invoke it? [duplicate]
class MyClass {
propOne = 'prop 1'
doSomething() {
console.log('executing doSomething')
console.log(this.propOne)
}
example1() {
setTimeout(() => { ...
0
votes
0
answers
14
views
This Keyword inside Callback Function [duplicate]
I have a newbie question.
For some reason my code can't access the value stored in the keyword: this.Selector (last line of code). I think it must have something to do that it's a callback function ...
0
votes
3
answers
40
views
'This' in a dynamic list using Jquery
I have a script that works for updating plus or minus in a quantity selector in a dynamic list. But I need to convert the code so that it only updates the 'current' list item quantity not all of them ...
0
votes
1
answer
43
views
Why can't I access a declared variable in the global scope [duplicate]
var bar = {
myName: 'bar',
printName: function () {
console.log(this.myName)
}
}
function foo() {
let myName = 'foo'
...
2
votes
0
answers
66
views
Why are we not allowed to access the value of an object through a glvalue that is not obtained through the constructor's this pointer
Recently I learnt that:
During construction of an object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the ...
5
votes
3
answers
185
views
Does a constructor also have an implicit this parameter
I am learning about classes in C++ and know that non-static member functions have implicit this parameter. My first question is that does constructor also have an implicit this parameter just like non-...
5
votes
1
answer
113
views
this pointer cannot be aliased in a constructor:
I am learning about inheritance in C++. And i came across the following statement:
In other words, the this pointer cannot be aliased in a constructor:
extern struct D d;
struct D
{
D(int a) : a(...
0
votes
0
answers
32
views
Why does this.value return undefined but works fine if put inside a function? [duplicate]
I'm learning javascript, I'm new to programming and i was wondering about "this".
let someObject = {
a : "happy",
b : "sad",
c : function(){
return ...
0
votes
1
answer
21
views
p5.js returns UNDEFINED on this.instance_variable however, works when called explicitly. Please explain why. Example provided
I have read some stack overflow and all I was able to find was that "this" was not referencing the instance variable I had in question and that it was referencing the current window. This ...
0
votes
4
answers
86
views
How to refer to component object within intercept/arrow function?
Here's my code:
export class NetworkInterceptor implements HttpInterceptor {
constructor(private router: Router, private ngZone: NgZone) {}
intercept(request: HttpRequest<unknown>, next: ...
0
votes
0
answers
9
views
Why does this array destructuring not work when assigning to 'this'? [duplicate]
I have a class that runs a function cloneButtons during construction. The cloneButtons function takes an array oldButtons and returns an array newButtons of the same exact elements. My problem is that ...
1
vote
1
answer
24
views
Can I use "this" to have a class input itself in a method call from a different class? [duplicate]
I'm trying to make a checkers game as practice for personal reasons, as I am somewhat newer to Java and am trying to learn.
In class Board, I'm trying to call a method that requires a Board type as ...
0
votes
1
answer
50
views
Contradicting definition of implicit this parameter in the standard
I am learning about classes in C++. I came across the following statement from the standard:
During overload resolution, non-static cv-qualified member function of class X is treated as a function ...
1
vote
1
answer
37
views
linked list c++ difference between void function and return this
I have a question about the differences between 2 styles of coding:
void *addfirst (int data){
head = new Node(int data, head);
return;
}
and the second is:
LinkedList *addfirst (int data){
...
0
votes
0
answers
35
views
Why `a` can be printed from `baz`? [duplicate]
const Foo = function(a){
// bar doesn't belong to any instance
function bar(){
console.log(a);
};
this.baz = function(){
console.log(a);
}
}
const f = new Foo(7);
f.baz() // print ...
0
votes
1
answer
35
views
setter method giving an error due to this keyword
The program is throwing an error in the setter method possibly due to the use of this keyword. Why is it giving an error?
The error: Method call setAge(-5), set a field value of "-5" but &...
0
votes
3
answers
34
views
How to access an object from an object nested function with this keyword?
I have this object:
popup_data = {
club: {
type: 'club',
type_img: {
header: 'CLUB HEADER',
img: 'https://source.unsplash.com/random/800x600',
...
-2
votes
1
answer
73
views
where the keyword "this" refer to in sapui5 [duplicate]
I read below codes and try to understand keyword this refer to which object.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"sap/ui/model/json/...