this

How do I access JavaScript this from ScriptSharp?

為{幸葍}努か 提交于 2020-01-06 03:03:04
问题 I'm trying to do the following. var handler = e => { handle(); item.Unbind("event", this); } item.Bind("event", handler); In JavaScript this would properly work, but ScriptSharp replaces JavaScript's this with reference to the instance of class containing method with that code. How do I avoid this behavior and get a reference to the lambda from the lambda itself? 回答1: Here's how you could do it (assuming Bind takes a delegate with the signature of an Action): SomeObject item = ...; Action

java - how to fix the “leaking this in constructor” warning [duplicate]

夙愿已清 提交于 2020-01-05 09:04:41
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java - Leaking this in constructor In the NetBeans I have a JDialog that contains a JPanel. I am trying to pass a reference of the JDialog to the JPanel. Please take a look at my code below. When I do it the way I did I receive the "Leaking this in constructor" warning. I understand why, but I don't know how to fix this. I also know that I can use @SuppressWarnings("LeakingThisInConstructor") but isn't there a

java - how to fix the “leaking this in constructor” warning [duplicate]

别来无恙 提交于 2020-01-05 09:04:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java - Leaking this in constructor In the NetBeans I have a JDialog that contains a JPanel. I am trying to pass a reference of the JDialog to the JPanel. Please take a look at my code below. When I do it the way I did I receive the "Leaking this in constructor" warning. I understand why, but I don't know how to fix this. I also know that I can use @SuppressWarnings("LeakingThisInConstructor") but isn't there a

KnockoutJS computed observable within an observable

被刻印的时光 ゝ 提交于 2020-01-05 05:03:35
问题 I have a ViewModel containing the following observable: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable("") }); Now I want to add a new computed observable to obFoo that depends on both foo and bar, something like this: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable(""), foobar: ko.computed(function(){ return foo() + bar(); }) }); The problem is that foo and bar are not defined within the scope of foobar. I tried adding 'this' or even 'self

JavaScript function call/apply with string

ε祈祈猫儿з 提交于 2020-01-04 11:10:26
问题 I just noticed that, when I want to pass string as "this" , the type cannot be obtained correctly inside a JavaScript function. Here is an example: var str = 'string value'; if (typeof (str) == 'string') { alert('string outside'); } var fn = function(s) { if (typeof (str) == 'string') { alert('string param'); } if (typeof (this) == 'string') { alert('string this'); } else { alert(typeof(this)); } }; fn.call(str, str); I see 3 messages: "string outside" , "string param" , and "object" . My

javascript this object

假装没事ソ 提交于 2020-01-03 11:48:43
问题 I have been working on web project for past 4 months. To optimise the code performance we have used a pattern. My doubt is, does it actually boost performance or not? when ever we have to use this object we assign it to a local variable, and use that. function someFunction() { var thisObject = this; //use thisObject in all following the code. } the assumption here is that, assigning this object to a local stack variable will boost the performance. I have not seen this type of coding anywhere

javascript this object

心不动则不痛 提交于 2020-01-03 11:48:16
问题 I have been working on web project for past 4 months. To optimise the code performance we have used a pattern. My doubt is, does it actually boost performance or not? when ever we have to use this object we assign it to a local variable, and use that. function someFunction() { var thisObject = this; //use thisObject in all following the code. } the assumption here is that, assigning this object to a local stack variable will boost the performance. I have not seen this type of coding anywhere

In which case the C++ this pointer can be NULL

﹥>﹥吖頭↗ 提交于 2020-01-03 08:32:12
问题 I experienced an issue that in the class constructor while I was using this pointer, but this pointer happen to be NULL at that time. for example MyClass::MyClass() { //this pointer happen to be NULL in this case, and it crash in teh m_callbackfunc because it does not handle null input. m_callbackFunc(this); } I wonder why this pointer can be null? and in which case this pointer can be null? 回答1: The only way a this pointer can be NULL is if some code in the program has exhibited undefined

In which case the C++ this pointer can be NULL

旧巷老猫 提交于 2020-01-03 08:32:00
问题 I experienced an issue that in the class constructor while I was using this pointer, but this pointer happen to be NULL at that time. for example MyClass::MyClass() { //this pointer happen to be NULL in this case, and it crash in teh m_callbackfunc because it does not handle null input. m_callbackFunc(this); } I wonder why this pointer can be null? and in which case this pointer can be null? 回答1: The only way a this pointer can be NULL is if some code in the program has exhibited undefined

Difference between static:: and $this::

风流意气都作罢 提交于 2020-01-03 08:07:38
问题 I know there is a difference between static:: and self:: like in this example ( from https://stackoverflow.com/a/13613718/2342518 ) <?php class One { const TEST = "test1"; function test() { echo static::TEST; } } class Two extends One { const TEST = "test2"; } $c = new Two(); $c->test(); Which returns test2 when static::TEST is used and test1 when self::TEST is used. But it also returns test2 when $this::TEST is used. static::TEST can be used inside a static method, whereas $this::TEST