przemek.ch wrote:
^^^^^^^^^^
I usually don't talk to domains. Please put a name there, preferably a
real one.
example first
var a = {
b : {
x : " test"
}
};
a.someMethod = function(){
alert(this.b.x);
Should be
window.alert(this.b.x);
(See previous discussions.)
}
This code works but...
I was wondering about few things
1) eclipse jsdt validator shows that
this.b.x - x should not be accessed in static way - why?
AISB, previous versions of JSDT were written by IBM developers with, it
appeared so, primarly Java background and little understanding of
ECMAScript, trying to validate against a lot of concepts of Java that do
not apply to ECMAScript implementations, even if user preferences
suppressed the corresponding warnings or error messages.
Therefore, I suggest you update to at least JSDT 1.2.0¹ where handling of
ObjectLiterals was considerably improved (including the Outline View).
Enabling all warnings for JavaScript validation, the only warnings I get
there are:
- "Non-externalized string literal" in line 3
- "Missing semicolon" in line 9
I am using the following JSDT Validator default settings instead:
* Errors/Warnings:
Everything set to "Warning" except the following set to "Ignore":
- Parameter assignment
- Non-externalized strings
- Uninitialized global variables
- Local variable declaration hides another field or variable
* JSDoc:
- [x] Process JSDoc comments
- Malformed JSDoc comments: Warning
- Only consider members as visible as: Default
- [x] Report errors in tags
- [_] Report non-visible references
- [x] Report deprecated references
- Missing JSDoc tags: Ignore
- Missing JSDoc comments: Ignore
These defaults avoided spurious warnings and error messages with previous
JSDT versions, so some of them might be worth modifying with newer version
(however, I can still find nothing wrong in assigning to arguments as it
saves me one variable declaration for each default argument value; YMMV).
2) is that a correct way of object declaration? especially that nested
b object
Objects are *not* declared, they are _constructed_. Objects have an
identity, not a name.
Here you are declaring the _variable_ `a' which, after the assignment,
holds a _reference_ to a newly constructed object (which `b' _property_
holds a _reference_ to another newly constructed object that has an `x'
property that holds a primitive string value).
And yes, this code is syntactically correct in many implementations (try it
out).³ Whether it is also semantically correct depends on your use case.
HTH
PointedEars
___________
¹ org.eclipse.wst.jsdt.feature.feature.group
1.2.0.v200912170603-771FEcCcNBEbBTMQCXO_
in EPP PHP Feature (org.eclipse.epp.package.php.feature.feature.group)
1.3.0.20100201-1819
in Eclipse IDE for PHP Developers (epp.package.php) 1.3.0.20100201-1819
for Eclipse 3.6M5+ (Helios; I installed EPP for M5¹ but did a full update
afterwards, so this JSDT version might be for M6)
² <
http://www.eclipse.org/downloads/>, "Development" tab
³ <
http://PointedEars.de/es-matrix>