OLD | NEW |
1 this.foo = this.foo + 1; // OK - outside of function. | 1 this.foo = this.foo + 1; // OK - outside of function. |
2 | 2 |
3 function f() { | 3 function f() { |
4 this.foo = this.foo + 1; // OK - global |this|. | 4 this.foo = this.foo + 1; // OK - global |this|. |
5 } | 5 } |
6 | 6 |
7 /** | 7 /** |
8 * @constructor | 8 * @constructor |
9 */ | 9 */ |
10 function TypeOne() { | 10 function TypeOne() { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 */ | 139 */ |
140 function callback() { | 140 function callback() { |
141 this.bar = this.bar + 1; // OK - @this declared. | 141 this.bar = this.bar + 1; // OK - @this declared. |
142 } | 142 } |
143 }, | 143 }, |
144 | 144 |
145 funcThree: function() { | 145 funcThree: function() { |
146 function badCallbackInMethod() { | 146 function badCallbackInMethod() { |
147 this.bar = this.bar + 1; // ERROR - @this not declared. | 147 this.bar = this.bar + 1; // ERROR - @this not declared. |
148 } | 148 } |
| 149 |
| 150 /** |
| 151 * @this {TypeOne} |
| 152 */ |
| 153 function callbackNotReferencingThis() { |
| 154 return 3; // ERROR - @this for a function not referencing |this|. |
| 155 } |
149 } | 156 } |
150 } | 157 } |
151 | 158 |
152 return new TypeThree(); | 159 return new TypeThree(); |
153 } | 160 } |
154 | 161 |
155 var object = { | 162 var object = { |
156 /** | 163 /** |
157 * @this {MyType} | 164 * @this {MyType} |
158 */ | 165 */ |
159 value: function() | 166 value: function() |
160 { | 167 { |
161 this.foo = 1; // OK - @this annotated. | 168 this.foo = 1; // OK - @this annotated. |
162 } | 169 } |
163 }; | 170 }; |
164 | 171 |
165 (function() { | 172 (function() { |
166 var object = { | 173 var object = { |
167 /** | 174 /** |
168 * @this {MyType} | 175 * @this {MyType} |
169 */ | 176 */ |
170 value: function() | 177 value: function() |
171 { | 178 { |
172 this.foo = 1; // OK - @this annotated. | 179 this.foo = 1; // OK - @this annotated. |
173 } | 180 } |
174 }; | 181 }; |
175 })(); | 182 })(); |
| 183 |
| 184 /** |
| 185 * @constructor |
| 186 */ |
| 187 var ReceiverTest = function() {} |
| 188 |
| 189 ReceiverTest.prototype = { |
| 190 memberOne: function() { |
| 191 var badMemberBinding1 = this.memberTwo.bind(null); // ERROR - Member not
bound to |this| receiver. |
| 192 var badMemberBinding2 = this.memberTwo.bind(bar); // ERROR - Member not
bound to |this| receiver. |
| 193 var goodMemberBinding = this.memberTwo.bind(this); |
| 194 |
| 195 /** @this {ReceiverTest} */ |
| 196 function callbackWithThis() |
| 197 { |
| 198 this.memberTwo(); |
| 199 } |
| 200 |
| 201 function callbackNoThis() |
| 202 { |
| 203 return 42; |
| 204 } |
| 205 |
| 206 callbackWithThis.call(this); |
| 207 callbackWithThis.call(foo); |
| 208 callbackNoThis(); |
| 209 callbackNoThis.call(null, 1); |
| 210 callbackNoThis.apply(null, [2]); |
| 211 callbackNoThis.bind(null, 1); |
| 212 this.memberTwo(callbackWithThis.bind(this, 1)); |
| 213 this.memberTwo(callbackWithThis.bind(foo, 1)); |
| 214 this.memberTwo(callbackNoThis); |
| 215 this.memberTwo(callbackNoThis.bind(null)); |
| 216 |
| 217 callbackWithThis(); // ERROR - No receiver. |
| 218 callbackWithThis.call(); // ERROR - No receiver. |
| 219 callbackWithThis.call(null); // ERROR - No receiver. |
| 220 callbackWithThis.apply(); // ERROR - No receiver. |
| 221 callbackWithThis.apply(null); // ERROR - No receiver. |
| 222 callbackNoThis.call(this); // ERROR - Function has no @this annotation. |
| 223 callbackNoThis.call(foo); // ERROR - Function has no @this annotation. |
| 224 callbackNoThis.apply(this); // ERROR - Function has no @this annotation. |
| 225 callbackNoThis.bind(this); // ERROR - Function has no @this annotation. |
| 226 |
| 227 this.memberTwo(callbackWithThis); // ERROR - Used as argument with no bo
und receiver. |
| 228 this.memberTwo(callbackWithThis.bind(null, 2)); // ERROR - Used as argum
ent with no bound receiver (null means "no receiver"). |
| 229 this.memberTwo(callbackNoThis.bind(this)); // ERROR - Bound to a receive
r but has no @this annotation. |
| 230 this.memberTwo(callbackNoThis.bind(foo)); // ERROR - Bound to a receiver
but has no @this annotation. |
| 231 }, |
| 232 |
| 233 memberTwo: function(arg) {} |
| 234 } |
OLD | NEW |