this

Access member field with same name as local variable (or argument)

 ̄綄美尐妖づ 提交于 2019-12-05 12:03:25
Consider following code snippet: struct S { S( const int a ) { this->a = a; // option 1 S::a = a; // option 2 } int a; }; Is option 1 is equivalent to option 2? Are there cases when one form is better than another? Which clause of standard describes these options? option 1 is equivalent to option 2, but option 1 will not work for a static data member EDITED: static data members can be accessed with this pointer. But this->member will not work in static function. but option 2 will work in static function with static member Eg: struct S { static void initialize(int a) { //this->a=a; compilation

why is this.callParent(arguments); called at the beginning of the constructors in ExtJS?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 11:33:43
问题 I noticed that in a lot of the programs I have been modifying recently they always call the parent arguments of the current object. I know that this is needed but don't have a solid understanding as to why this is a common practice. Any wisdom out there for a junior level developer... I should know this. 回答1: This is the mechanism that ExtJS uses to support class inheritance in constructors. Calling this.callParent(arguments) in a constructor calls the constructor of the immediate parent

“this” keyword doesn’t seem to work

落爺英雄遲暮 提交于 2019-12-05 10:36:45
I am trying to understand how the this keyword works in JavaScript and I made this script: function click(){ this.innerHTML="changed"; } Used in this HTML: <button id="clicker" onclick="click()" >Click me</button> But it doesn't work, can anyone explain why? this exists only in the scope of the onclick event itself. It is not bound automatically to other functions. Pass it on like this: function click(element){ element.innerHTML="changed"; } and the html: <button id="clicker" onclick="click(this)" >Click me</button> You function click doesn't know about 'this'. Change it to: function click

A puzzle about this/@ in Javascript/Coffeescript

点点圈 提交于 2019-12-05 10:23:46
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 as Coffeescript then as Javascript: // coffeescript setName = (name) -> @name = name setName 'Lulu'

When calling a Javascript function, how do I set a custom value of “this”?

懵懂的女人 提交于 2019-12-05 10:07:28
I'm using jQuery and I have a function that serves as an event callback, and so in that function "this" represents the object that that captured the event. However, there's an instance where I want to call the function explicitly from another function - how do I set what "this" will equal within the function in this case? For example: function handleEvent(event) { $(this).removeClass("sad").addClass("happy"); } $("a.sad").click(handleEvent); // in this case, "this" is the anchor clicked function differentEvent(event) { $("input.sad").keydown(e) { doSomeOtherProcessing(); handleEvent(e); // in

Java Inheritance - this keyword

做~自己de王妃 提交于 2019-12-05 08:31:19
I searched online for similar question, but could not find it. So, posting here. In the following program why the value of 'i' is printed as 100? AFAIK 'this' refers to the current object; which in this case is 'TestChild' and the class name is also correctly printed. But why the value of the instance variable is not 200? public class TestParentChild { public static void main(String[] args) { new TestChild().printName(); } } class TestChild extends TestParent{ public int i = 200; } class TestParent{ public int i = 100; public void printName(){ System.err.println(this.getClass().getName());

What do these “this” mean in this JavaScript code?

有些话、适合烂在心里 提交于 2019-12-05 08:14:57
问题 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <script type="text/javascript" charset="utf-8"> (function(){ // this var test=function(){ //this return function(){ //this }; } (function(){ //this var a={ p1:function(){ //this } }; })(); })(); </script> </body> </html> 回答1: David Dorward already mentioned about

Aptana 3.4.2 安装jQuery支持时遇到的挫折与解决方案

谁说胖子不能爱 提交于 2019-12-05 07:46:01
今天想在 Aptana 上安装 jQuery 包(Bundle),在安装过程中遇到了一些小小的问题。经过一番 Google,终于安装成功了,在此记录下来共享给需要的同学。 根据不同版本的 Aptana,安装 jQuery 的方法不同。 Aptana 3.0.5 以下的 Aptana 3 需要使用第一种方法,而 3.0.5 以上的版本可以使用两种方法的任意一个,建议使用第二种方法安装。 方法一 点击以下链接中的一个,建议下载 1.6.2。 1.4.2: https://github.com/aptana/javascript-jquery.ruble/blob/master/support/jquery.1.4.2.sdocml 1.6.2: https://github.com/aptana/javascript-jquery.ruble/blob/master/support/jquery.1.6.2.sdocml 点击后如图 点击复制按钮,以复制所有内容。 然后打开本地记事本,将复制的内容粘贴到记事本里,并保存为 jquery.1.6.2.sdocml。这里 特别注意后缀名必须是.sdocml ,而不是默认的 txt 文件! 将这个文件放在你项目中的任何目录中,一般是放在项目的根目录下。 安装完成!!! 缺点: 手动安装无法自动升级 每个项目中都要手工复制这个文件 优点: 简单

How can “this” be referenced/processed before the constructor has concluded?

霸气de小男生 提交于 2019-12-05 07:21:24
The specific use where I thought of this problem is as follows, but it's much more generalized. I have a custom JFrame class which also serves as an ActionListener for its components. So my constructor looks something like the following: private JButton myButton; public MyCustomFrame() { super(); myButton.addActionListener(this); // ... more stuff } My question is, how does this actually work behind the scenes? If the constructor is what "creates" the object which is referenced by this , how can I use this before the constructor has returned? The code compiles and works perfectly fine (as far

Why can't I pass the this pointer explicitly to a member function?

巧了我就是萌 提交于 2019-12-05 06:20:48
The c++ standard (ISO c++11) mentions in Section 9.3.1 that A non-static member function may be called for an object of its class type, or for an object of a class derived (Clause 10) from its class type, using the class member access syntax (5.2.5, 13.3.1.1). An attempt to compile this code with g++ (version 4.8.2) class foo{ public: void bar(){ cout<<"hey there"<<endl; } }; int main(){ foo obj; foo::bar(&obj); } gives a compile time error because it couldn't match the function's signature. I guess that is expected given what the standard states about calling member functions. Since the