this

Changing what THIS is

谁说胖子不能爱 提交于 2019-12-10 23:49:33
问题 Is there a way to change what THIS point to? class foo{...} foo* fooinstance = new foo(); foo* otherfooinstance = new foo(); void foo::bar(){ this = otherfooinstance; } fooinstance->bar(); for those of you who are wondering in what case I would change the this pointer here is case. I had to do a tree recursion where I had to remove intermediate nodes.. for this example lets assume the intermediate nodes of removal have the title d. and these intermediate nodes only have one child. So in lisp

How can i refer the object on jQuery?

♀尐吖头ヾ 提交于 2019-12-10 23:17:15
问题 I'm making a script which has one ajax call inside an each function. The problem is that on the success callback from ajax call, I want to use the object that we are using at each function. EDIT: Here is some of my code: configs={ general:{ max_ads:6}, logs:{ selector:"div#MicrodualGetAd-debug"}, connection:{ type:"POST", url:"http://www.microdual.com/api/microdualgetad", cache:false, timeout:20000, dataType:"json", data:{ adget_id:null, adget_session:null, client_action:null}, error:function

Javascript Inheritance and losing the context of 'this'

拜拜、爱过 提交于 2019-12-10 19:59:06
问题 I am using John Resig's Simple JavaScript Inheritance and have run into an issue where I am losing what 'this' refers to. Using this code: var Runner = Class.extend({ init: function() { this.update(); if(!this.interval) { this.interval = setInterval(this.update, this.period * 1000); } }, stop: function() { clearInterval(this.interval); }, update: function() { this.success() }, success: function(){ } }); var SubRunner = Runner.extend({ update: function() { this._super(); }, success: function()

Typescript “this-typing” confusion

余生颓废 提交于 2019-12-10 19:49:38
问题 I am referring to "this-typing" referenced here, and here. It is my understanding that using this as a type refers to the current class, or whatever is left of the dot (thereby allowing inherited methods to refer to their own class instead of their parent's class). So can someone explain why this doesn't work: class Test { children: Array<this>; constructor() { this.children = [new Test()]; } } (My goal is to do that with an inherited class, but it doesn't work with a base class. Since this

Is it ok to dynamic cast “this” as a return value?

…衆ロ難τιáo~ 提交于 2019-12-10 19:26:41
问题 This is more of a design question. I have a template class, and I want to add extra methods to it depending on the template type. To practice the DRY principle, I have come up with this pattern (definitions intentionally omitted): template <class T> class BaseVector: public boost::array<T, 3> { protected: BaseVector<T>(const T x, const T y, const T z); public: bool operator == (const Vector<T> &other) const; Vector<T> operator + (const Vector<T> &other) const; Vector<T> operator - (const

Name hiding in constructor initialization list

五迷三道 提交于 2019-12-10 19:12:43
问题 I want to modify a constructor to use an initialization list as in the following example: class Foo { public: Foo(std::wstring bar); private: std::wstring bar; }; // VERSION 1: Foo::Foo(std::wstring bar) {this->bar = bar} // VERSION 2: Foo::Foo(std::wstring bar) : this->bar(bar) {} // ERROR! Unfortunately I can't do version 2 because you can't use the this pointer for data members since (I'm guessing) they don't exist yet at that point. How then, do I deal with the name hiding issue (i.e. my

how to reuse android alertdialog

北城余情 提交于 2019-12-10 18:48:00
问题 I want to reuse the code for alertDialog and put it in another java file as function call . But "this" cannot be used to replace the "MyActivity.this"? How to pass it as a parameter? Best if the code is generic. AlertDialog alertDialog = new AlertDialog.Builder(MyActivity.this).create(); alertDialog.setTitle("Alert"); alertDialog.setMessage("Alert message to be shown"); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick

Multiple inheritance and the this pointer

筅森魡賤 提交于 2019-12-10 18:33:40
问题 Suppose I have this struct: struct vector_data { double x, y; double& operator[](size_t index) { return * (static_cast<double*>(static_cast<void*>(this)) + index); } }; The operator[] should work as expected, because vector_data is a POD type. The expected behaviour is that vector_data[0] returns x, and vector_data[1] returns y. Now suppose I have a second struct: struct more_data { double evil_data; // There could be more here, data or functions }; And derive from both like this: struct

this inside prototype function equal to window instead of object instance

可紊 提交于 2019-12-10 16:27:52
问题 In the following code in HeadDirective.prototype.link , this is equal to the global window object rather than the HeadDirective instance. My understanding is that the value of this inside a prototype function is the containing object itself. var HeadDirective = (function () { function HeadDirective($rootScope, $compile) { this.$rootScope = $rootScope; this.$compile = $compile; this.restrict = 'E'; } HeadDirective.prototype.link = function (scope, elem) { var html = '<link rel="stylesheet" ng

Confused about the 'this' keyword in javascript

a 夏天 提交于 2019-12-10 15:58:44
问题 I haven't used Javascript in a long time and have been refreshing myself on it today. One thing that always got me was the this keyword. I know in jQuery event handlers, such as the click event, this refers to the element that fired the event. How is this passed to the function that I give it as a callback even though my function has no arguments? Given the following code: $("tr.SummaryTbRow").data("Animating", false); $("tr.SummaryTbAltRow").data("Animating", false); $("tr.SummaryTbRow")