this

Why different behavior for “TYPE* const” pointers?

萝らか妹 提交于 2019-12-02 03:18:11
Below code is dealing with a TYPE* const pointer. struct D { void Check () { D* const p = new D; // 2nd test is "p = 0;" cout<<"p = "<<p<<endl; (D*&)p = new D; cout<<"p = "<<p<<endl; // prints 0, "p = 0;" at declaration } }; int main () { D o; o.Check(); } My questions are, If you initialize with 0 , then even though typecasting next time will not work. Is doing such typecasting is undefined behavior ? this pointer is also of TYPE* const type, then why compiler doesn't allow the same operation for this ? As others have said, this is undefined behaviour since it attempts to modify a const

Javascript this keyword - inside function

牧云@^-^@ 提交于 2019-12-02 02:42:13
I am trying to understand the this keyword on Javascript . I was doing some tests on chrome console and I came across two different results that I was expecting to be the same: var myTest = {}; myTest.test1 = function() { return this; // this = Object } This first function returns myTest object which I understand. var myTest = {}; myTest.test1 = function() { return function test2() { return this; // this = Window } } Why is the second function returning the window instead of the myTest object? Thank you this refers to the current object on which the function is called. When you called test1 ,

Does 'this' refer to the element that called this function?

主宰稳场 提交于 2019-12-02 02:24:28
In the snippet below I use $(this) to refer to the element in which the function is being called from. I know it is not correct because I printed out the values and it gave me 'undefined'. How do I refer to the input element? $(function() { $( ".datepicker" ).datepicker({ onSelect: function (date, obj){ if(confirm('Is this correct?: '+ date )) { $.post('edit.php', { "row": $(this).data('id'), "date":date, "field":$(this).name, "ajax":'true' }); } } }); }); Here is the html element: <input name="appvAcadVp" data-id="someid" class="datepicker" size="10" type="text" placeholder="someholder" >

Javascript this keyword - inside function

流过昼夜 提交于 2019-12-02 01:33:08
问题 I am trying to understand the this keyword on Javascript . I was doing some tests on chrome console and I came across two different results that I was expecting to be the same: var myTest = {}; myTest.test1 = function() { return this; // this = Object } This first function returns myTest object which I understand. var myTest = {}; myTest.test1 = function() { return function test2() { return this; // this = Window } } Why is the second function returning the window instead of the myTest object

How to change what an ES6 arrow function's 'this' points to?

允我心安 提交于 2019-12-02 01:21:11
In the traverse npm package there's this example var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; traverse(obj).forEach(function (x) { if (x < 0) this.update(x + 128); }); Inside the callback function you can call this.update . I know in these kinds of cases you should use the regular (not ES6 arrow) style of function definitions like shown above. But out of curiosity, how would you make that code work with ES6 arrow function syntax? If I try as follows I get TypeError: Cannot read property 'update' of undefined because of course this is not the same as above. traverse(obj)

what does $this mean within a class definition? [closed]

好久不见. 提交于 2019-12-01 23:40:25
As I continue to try and improve myself as a junior PHP developer, I have started to try break down other peoples work. I find it helps me understand, as well as giving me ideas. Two things I do not get, in a PHP class, what $this means, and what array($this,'some_function') means when I would expect a function name in it's place. Many thanks Gordon Please see the PHP Manual on Classes and Objects . $this refers to the object instance. Also see these questions: What does the variable $this mean in PHP? What is the meaning of $this For array($this,'some_function') see the PHP manual on

$(this) and this inside click-event

微笑、不失礼 提交于 2019-12-01 23:29:32
问题 i have an own js-class and try to use jquery's $(this) and object-this in an click-event. jquery's $(this) works fine, but the object-this is not defined. http://jsfiddle.net/j33Fx/2/ var myclass = function(){ this.myfunction = function(){ alert('myfunction'); } this.buttonclicked = function(){ alert('buttonclicked'); } this.writeout = function(){ var buttoncode = '<button class="mybutton">click</button>'; $('body').append(buttoncode); $('.mybutton').click(function(){ alert('Button: '+$(this)

Is it legal C++ to test the this-pointer in a member function?

微笑、不失礼 提交于 2019-12-01 22:23:13
问题 I have an application involving objects of different class types. The objects are referenced by pointers. A null pointer signifies that the associated object does not exist. Currently the calling codes is cumbersome, because each time it uses a pointer to an object, it tests the pointer value for null, and take some appropriate action it is null. Because the default action to be taken in the case of non-existence depends on the type of object, I would prefer to encode it in the classes for

Why “this” inside of a function's returning object window

前提是你 提交于 2019-12-01 22:16:45
there is two type of scope in javascript named function scope global scope now i am executing this code function abc() { alert(this); } abc(); abc call returning me [object Window] Why?? function makes another scope so why it is representing window this , inside any function, will be the object on which the function is invoked. In your case, you are not invoking it on any object. So, by default this refer to global object, in your browser, it is the window object. But in strict mode, if you invoke it like this, this will be undefined . "use strict"; function abc() { console.log(this); //

Can someone clarify Android context references?

送分小仙女□ 提交于 2019-12-01 21:49:41
问题 My misunderstanding continues ... Can anyone cite references for the proper use of get*Context() ? I get conflicting recommendations about using getBaseContext() , getApplicationContext() and getContext() and my understanding is that using this is a convenience to get*Context() . I would like to study more specifically of what Dalvik is intending its object and access methods. I had code reviews that changed my calls to getBaseContext() to getApplicationContext() , now I am seeing suggestions