ceh wrote:
Quote:
Perhaps I should have written
this.m_xmlhttp = "";
Assigning `null' would be more appropriate because ...
Quote:
and later set it to xmlhttp _object_ instance.
.... you would assign an object _reference_ and `null' is an object value
(the sole value of the Null type, representing "the null, empty, or
non-existent [object] reference"). But since there is no strict typing and
both values are false-values (i.e. type-convert to `false'), it does not
matter much. You could even omit the previous assignment and create the
property only when needed (there might be a bunch of warnings on prior read
access in Gecko-based UAs then, though).
I prefer initializing said properties with `null' instead of with other
false-values because it is intuitive and probably wastes a minimum amount of
memory ("" has String properties, `null' has none).
Quote:
in fact, why do people use this at all? Those vars will be in scope
regardless correct?
No, this has nothing to do with variables or the scope chain. With the
above you are creating or modifying a *property* of the Activation Object.
That object is the calling object or, in the constructor, the object that
is about to be created.
Quote:
If I can't declare variables via this.x = something, then why do all
my other uses of it work?
this.url = "";
For instance.
In the global execution context, the Activation Object (which `this' refers
to) is the Global Object. But the Global Object is also the Variable Object
of the global context, and so global variables are also properties of that
object. (In local execution contexts, i.e. in methods, unfortunately there
is no way to refer to the Variable Object.)
See the ECMAScript Language Specification, Edition 3 Final, sections 10.1.6
to 10.1.8, and 10.2.
Quote:
Are you suggesting that I always need var foo; ?
If you want a *variable* and not just a property, then yes.
Quote:
It seems there is a lot of code out there that uses the this methodology.
Maybe because of those people doing (explicit) OOP?
Quote:
If that is the case, then is this what I'd need?
>
var xmlHTTP;
xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
// use this one from now on.
this.m_xmlHTTP = xmlHTTP;
>
Or, just don't declare it until I set it?
this.m_xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
Impossible to say without you providing the context in which these
statements are to be executed. The context matters.
Please reply *below sections of trimmed quotes*, as explained and
recommended in the FAQ and FAQ Notes:
http://jibbering.com/faq/
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16