this

jQuery - 'this' selector doesn't work inside callback function [duplicate]

雨燕双飞 提交于 2020-02-07 12:27:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: $(this) doesn't work in a function I'm writing post removing code in jQuery, The removing itself is made via post-request to backeds, after server returns 200, I want to delete this post on client-side. $('.delete-post').click(function() { $.post($(this).attr('href'), {}, function(data) { $(this).closest('.post').remove(); }); return false; }); However, I've noticed that inside function(data) {...) selector

implicit object parameter and this pointer

时光总嘲笑我的痴心妄想 提交于 2020-02-04 20:58:33
问题 With reference to Non-static member functions, under const-, volatile-, and ref-qualified member functions it is mentioned: A non-static member function can be declared with no ref-qualifier, with an lvalue ref-qualifier (the token & after the parameter list) or the rvalue ref-qualifier (the token && after the parameter list). During overload resolution, non-static cv-qualified member function of class X is treated as follows: no ref-qualifier: the implicit object parameter has type lvalue

A puzzle about this/@ in Javascript/Coffeescript

孤街醉人 提交于 2020-02-02 02:55:32
问题 I'm working through Trevor Burnham's CoffeeScript book and I've run into a weird puzzle concerning this / @ . The puzzle has a few parts (and I may be just very confused), so I'll try to make this as clear as I can. The main problem I'm having is that I get varied and inconsistent results running the same code through different REPLs and interpreters. I'm testing with (1) the coffee REPL and interpreter, (2) Node's REPL and interpreter and (3) v8's REPL and interpreter. Here's the code, first

How to bind 'this' to functions outside react class which is a callback from other component?

社会主义新天地 提交于 2020-01-30 12:26:46
问题 I have a React Component such as : function callback(params){.. // I need to use this.setstate but this callback function is called // from other component. How do I bind value of this here // 'this' of RespProperties ... } class RespProperties extends Component { .. ... } This callback function is called from some other component. How do I bind value of 'this' here so that it can use states of this component? 回答1: I don't really understand the question. I don't know if this is what you mean,

Callback this context [duplicate]

泄露秘密 提交于 2020-01-30 02:47:20
问题 This question already has answers here : How to access the correct `this` inside a callback? (10 answers) Closed 3 years ago . in App: var bootstrap = new Bootstrap(); bootstrap.init( this, this.onBootstrapComplete ); in Bootstrap: this.init = function( app, completeHandler ){ _app = app; _completeHandler = completeHandler; ... } ... var _allReady = function(){ _completeHandler( _app ); } back in App: this.onBootstrapComplete = function( app ) { app.something(); app.someValue = ... } I wanted

'this' different between REPL and script

笑着哭i 提交于 2020-01-26 08:11:16
问题 After reading through mozilla docs I found this: In the global execution context (outside of any function), this refers to the global object, whether in strict mode or not. After playing with scopes for a little I found that in node.js REPL... > this === global true but when I create a script with the same line... $ cat > script.js console.log(this === global) $ node script.js false Is there a reason for this? Or is it a bug? 回答1: Node's REPL is global. Code from a file is in a "module",

Use arrow functions in jQuery plugin

无人久伴 提交于 2020-01-25 20:58:46
问题 I am writing a jQuery plugin. But it doesn't seem to work when I use arrow function to extend jQuery. This works : $.fn.extend({ func: function (params) { var ob = $(this); var selector = $(this).selector; var defaults = { }; params = $.extend(defaults, params); generate(ob, selector, params); } }); But when I try to use arrow function, it returns me the window object : $.fn.extend({ func: (params) => { var ob = $(this); // returns window object var selector = $(this).selector; var defaults =

How can I retrieve the text of a clicked element using jQuery's .text property?

南笙酒味 提交于 2020-01-24 05:21:06
问题 I currently have a list of divs that all have unique text. I would like the website to display the value of the text inside the div that you just clicked in a different div. The thing is, this list is very long, and I do not have specific IDs for any values in the list. Is it possible to pull text from that list using $(this).text ? I could not get it to work. HTML: <!DOCTYPE html> <html> <head> <title>Facilities Management</title> <link rel='stylesheet' type='text/css' href='stylesheet.css'/

this keyword is window object within a constructor function

前提是你 提交于 2020-01-24 03:10:28
问题 Ok, so I thought I understood this (no pun intended), but apparently not. var Constructor = function () { var internalFunction = function () { return this === window; }; this.myMethod = function () { alert(internalFunction()); }; }; var myObj = new Constructor(); myObj.myMethod(); This alerts true . Why can't the internal function see this as the object? Instead I have to use alert(internalFunction.call(this)); in myMethod . Edit: I was looking for an explanation as to why this is assigned in

Is `this` keyword optional when accessing members in C#?

。_饼干妹妹 提交于 2020-01-21 11:01:34
问题 I notice that if you have a private member in a class, you can access it in the class methods by just referring to it's name. You do not need to say this.memberName , just memberName works. So is the this keyword optional in the context of member access? I do see it is useful when you want to clarify the scope - when you have 2 variables with the same name. Is there any other reason to use it when accessing members? 回答1: Yes, it's optional. The only times you'd have to use it are when you