this

C# StyleCop - Using “this.” prefix for base class members like current class members or not?

喜欢而已 提交于 2019-12-22 04:36:12
问题 StyleCop has a rule about using "this." prefix to calling class members (SA1101). Is this rule holds true about a member (for example a method) of a class which is inherited from its base class. Example: class BaseClass { protected void F1() { ... } } class ChildClass : BaseClass { protected void F2() { ... } protected void F3() { this.F2(); // This is correct acording to SA1101 // F1 is a member of base class and if I dont put this prefix, stylecop will not show any message. this.F1(); // Is

C# StyleCop - Using “this.” prefix for base class members like current class members or not?

早过忘川 提交于 2019-12-22 04:36:09
问题 StyleCop has a rule about using "this." prefix to calling class members (SA1101). Is this rule holds true about a member (for example a method) of a class which is inherited from its base class. Example: class BaseClass { protected void F1() { ... } } class ChildClass : BaseClass { protected void F2() { ... } protected void F3() { this.F2(); // This is correct acording to SA1101 // F1 is a member of base class and if I dont put this prefix, stylecop will not show any message. this.F1(); // Is

php - unset $this

让人想犯罪 __ 提交于 2019-12-22 04:08:20
问题 I've made a class that acts like an file wrapper. When user call delete method, i want to unset the object (actually $this). Is there a way (workaround) to do that? The manual said no, there is no way... 回答1: As far as I know, there is no way to destroy a class instance from within the class itself. You'll have to unset the instance within its scope. $myClass = new fooBar(); unset($myClass); Somewhat related: Doing the above will automatically call any existing __destruct() magic method of

Is it good or bad to delegate to another constructor (using this()) within a constructor

丶灬走出姿态 提交于 2019-12-21 20:34:11
问题 Oracle reference doesn't tell about best practice of this keyword while we overload constructors. Can anyone suggest the best practice for it? Option 1: delegate to another constructor public class A { private int x, y, z, p; public A() { this(1,1,1,1); } public A(int x, int y, int z, int p) { this.x = x; this.y = y; this.z = z; this.p = p; } } and Option 2: set each field rather than delegating public class A { private int x, y, z, p; public A() { this.x = 1; this.y = 1; this.z = 1; this.p =

Scala: How can I create a function that allows me to use dot notation when calling it?

a 夏天 提交于 2019-12-21 19:49:08
问题 I have been confused about this for a while, even despite reading the Scala Style Guide - Method Invocation several times. I want to be able to call this method def foldRVL[A,B](l: List[A], z: B)(f: (A, B) => B) = //"Right-Via-Left" l.reverse.foldLeft(z)((a, b) => f(b, a)) using dot notation like this List(1,2,3).foldRVL(0)(_ + _) . And not like this: foldRVL(List(1,2,3), 0)(_ + _) . Also, sometimes I've seen code that shows methods that actually either takes zero parameters in their

Nested functions & the “this” keyword in JavaScript

房东的猫 提交于 2019-12-21 19:27:52
问题 "The this keyword always refers to the object that the containing function is a method of." Great, sounds simple enough, but here's what I'm wondering about... For example: function func1() { function func2() { alert(this == window); // true } func2(); alert(this == window); // true } func1.func3 = function () { alert(this == window); // false alert(this == func1); // true }; func1(); func1.func3(); Now, since func1 is actually a method of the global ( window ) object (a function object

Way to execute jQuery member functions inside setTimeout without closure?

谁说我不能喝 提交于 2019-12-21 14:51:30
问题 I was trying to do something along these lines: setTimeout($('#element').hide,3000); which seems simple enough, but it is crippled by the "this" problem. I want to find a way to just pass the actual function as a parameter, without wrapping it in another function , e.g. I do not want to do this: setTimeout(function(){$('#element').hide();},3000); What I've tried: setTimeout($('#element').hide,3000); setTimeout($('#element').hide.apply(document),3000); /* jQuery docs say that document is the

How to get 'this' value of caller function?

只愿长相守 提交于 2019-12-21 09:24:27
问题 If I have a function like this: function foo(_this) { console.log(_this); } function bar() {} bar.prototype.func = function() { foo(this); } var test = new bar(); test.func(); then the test instance of bar gets logged. However, for this to work I have to pass the this in the bar.prototype.func function. I was wondering whether it is possible to obtain the same this value without passing this . I tried using arguments.callee.caller , but this returns the prototype function itself and not the

C# Lambdas and “this” variable scope

大城市里の小女人 提交于 2019-12-21 07:14:14
问题 I am wondering whether I can use the this keyword inside a C# lambda, although actually I know that I can but I want to make sure that this isn't a bad thing or will produce subtle issues later on. Having read the rules on variable scope for lambdas, I can see that: A variable that is captured will not be garbage-collected until the delegate that references it goes out of scope. So this leads me to assume that an object instance ( this ) will also be captured. To test this I wrote this

Javascript `this` in objects-in-objects?

て烟熏妆下的殇ゞ 提交于 2019-12-21 06:19:08
问题 Sorry for fuzzy post title, I can't formulate the correct name in English for this post. For example I have such an object: var APP = { a : 1, b : function(){ return this.a; } } In such way, if I call console.log ( APP.b() ) than this will be referring to APP and result will be 1 . But how to connect to APP from sub-object? Example: var APP = { a : 1, b : function(){ return this.a; }, c : { c1: function(){ return APP.a; } } } console.log ( APP.c.c1() ) // 1 This example works, but it's bad