Why is ‘this’ a pointer and not a reference?

I was reading the answers to this question C++ pros and cons and got this doubt while reading the comments. programmers frequently find it confusing that “this” is a pointer but not a reference. another confusion is why “hello” is not of type std::string but evaluates to a char const* (pointer) (after array to pointer … Read more

React: “this” is undefined inside a component function

class PlayerControls extends React.Component { constructor(props) { super(props) this.state = { loopActive: false, shuffleActive: false, } } render() { var shuffleClassName = this.state.toggleActive ? “player-control-icon active” : “player-control-icon” return ( <div className=”player-controls”> <FontAwesome className=”player-control-icon” name=”refresh” onClick={this.onToggleLoop} spin={this.state.loopActive} /> <FontAwesome className={shuffleClassName} name=”random” onClick={this.onToggleShuffle} /> </div> ); } onToggleLoop(event) { // “this is undefined??” <— here this.setState({loopActive: … Read more

How can I exclude $(this) from a jQuery selector?

I have something like this: <div class=”content”> <a href=”#”>A</a> </div> <div class=”content”> <a href=”#”>B</a> </div> <div class=”content”> <a href=”#”>C</a> </div> When one of these links is clicked, I want to perform the .hide() function on the links that are not clicked. I understand jQuery has the :not selector, but I can’t figure out how to … Read more

How do I pass the this context to a function?

I thought this would be something I could easily google, but maybe I’m not asking the right question… How do I set whatever “this” refers to in a given javascript function? for example, like with most of jQuery’s functions such as: $(selector).each(function() { //$(this) gives me access to whatever selector we’re on }); How do … Read more