this

React- Cannot read property 'setState' of undefined

戏子无情 提交于 2019-12-03 12:23:56
for some reason, I'm getting the error " React- Cannot read property 'setState' of undefined". So this.state is never getting updated with the values that the user inputs. When I tried the binding that is commented out, I get strange behavior where I'm unable to type input for the username and I no longer get the null error, but the values are just undefined. Any help would be appreciated. Thanks. import __fetch from "isomorphic-fetch"; import React from "react"; import InlineCss from "react-inline-css"; import Transmit from "react-transmit"; import Header from './components/header' class

Java generics: Use this type as return type?

♀尐吖头ヾ 提交于 2019-12-03 12:03:25
I'm trying to make an API as user friendly as possible. Let's have: class B extends A {} class A { A setX(){ ...; return this; } } Now this B b = new B().setX(); is invalid, has to be casted: B b = (B) new B().setX(); Is there a way using generics in A to make compiler aware of "this" type and accept the first way - without casting and without passing type parameter at the place where used? (I.e. not new B<B>().setX() , that's ugly.) I KNOW why Java needs retyping in this case. Please no answers explaing that setX() returns A. I know that. I am asking if generics can solve this. And for those

Jquery select clicked element within a set of elements with the same classname

无人久伴 提交于 2019-12-03 11:58:21
Maybe you guys can help me out with this, I've been struggling with it for the past 30 minutes. Let's say I have four elements with the same class. <div class="test">hi</div> <div class="test">hey</div> <div class="test">yo</div> <div class="test">What's up</div> How can I select the one that was clicked on? I was able to get it work like this: $('.test').click(function() { $(this).toggleClass("btn-danger btn-success"); }); However, I need it to fire without being clicked on success after an ajax call, so I need to be able to do something like this (failed attempts): $('.test', this)

What is purpose of a “this” pointer in C++? [duplicate]

痴心易碎 提交于 2019-12-03 11:31:05
问题 This question already has answers here : When should I make explicit use of the `this` pointer? (12 answers) Closed 2 years ago . What is purpose of this keyword. Doesn't the methods in a class have access to other peer members in the same class ? What is the need to call a this to call peer methods inside a class? 回答1: Two main uses: To pass *this or this as a parameter to other, non-class methods. void do_something_to_a_foo(Foo *foo_instance); void Foo::DoSomething() { do_something_to_a_foo

jQuery remove selected option from this

大城市里の小女人 提交于 2019-12-03 10:38:46
问题 first post here, I come in peace :) I've searched but can't quite find what I'm after. I am trying to manipulate the selected option of a select box. Can someone please explain why this works: $('#some_select_box').click(function() { $('#some_select_box option:selected').remove(); }); but this doesn't: $('#some_select_box').click(function() { $('this option:selected').remove(); }); I just want to use "this" instead of spelling out the id of the select box - can someone point me in the right

How can I use multiple constructors to remove duplicated code while maintaining readability?

那年仲夏 提交于 2019-12-03 10:29:22
问题 int a, b, c; Constructor() { a = 5; b = 10; c = 15; //do stuff } Constructor(int x, int y) { a = x; b = y; c = 15; //do stuff } Constructor(int x, int y, int z) { a = x; b = y; c = z; //do stuff } To prevent duplication of "stuff" and a few assignments, I tried out something like: int a, b, c; Constructor(): this(5, 10, 15) { } Constructor(int x, int y): this(x, y, 15) { } Constructor(int x, int y, int z) { a = x; b = y; c = z; //do stuff } This works for what I want to do, but sometimes I

console.log() called on object other than console

时间秒杀一切 提交于 2019-12-03 09:24:11
I remember that always when I wanted to pass console.log as a callback parameter to some function, it didn't work unless I used the bind() method to bind console to it. For example: const callWithTest = callback => callback('test'); callWithTest(console.log); // That didn't use to work. callWithTest(console.log.bind(console)); // That worked (and works) fine. See Uncaught TypeError: Illegal invocation in javascript . However, recently I noticed that console.log() works fine even when called on object other than console. For example: console.log.call(null, 'test'); logs 'test' . When and why

Jquery - Expand image height and width 20% on hover

杀马特。学长 韩版系。学妹 提交于 2019-12-03 08:37:56
Evening all - Whats the best way to access an image's height and width dynamically . I want to add 20% to an images width and height and animate when the surrounding div is hovered, I guess I need to use 'this', but not sure how to access the image. Any help greatfully received. Cheers Paul You could do something like this, using .height() and .width() with function arguments: $("img").hover(function() { $(this).height(function(i, h) { return h * 1.2; }) .width(function(i, w) { return w * 1.2; }); }, function() { $(this).height(function(i, h) { return h / 1.2; }) .width(function(i, w) { return

Backbone.js with Google Maps - problems with this and listeners

风流意气都作罢 提交于 2019-12-03 07:48:55
问题 I have a module I created for Google Maps v3 that I'm trying to convert into a Backbone.js view constructor. Here's my view module so far: I'll explain the problems I'm having after the code: pg.views.CreateMap = Backbone.View.extend({ tagName: "div", className: "map", events: {}, latitude: "-23.56432", longitude: "-46.65183", initialize: function() { _.bindAll(this, 'render', 'dragMarker', 'dragMap'); this.latlng = new google.maps.LatLng(this.latitude, this.longitude); var myOptions = { zoom

How does the “this” keyword in Java inheritance work?

给你一囗甜甜゛ 提交于 2019-12-03 06:42:17
问题 In the below code snippet, the result is really confusing. public class TestInheritance { public static void main(String[] args) { new Son(); /* Father father = new Son(); System.out.println(father); //[1]I know the result is "I'm Son" here */ } } class Father { public String x = "Father"; @Override public String toString() { return "I'm Father"; } public Father() { System.out.println(this);//[2]It is called in Father constructor System.out.println(this.x); } } class Son extends Father {