Thomas said:
As for the former, I concur. As for the latter, one should
keep in mind that every function is indeed a method (ES3
Final, 4.3.3) in ECMAScript implementations -
Every function?
(function(){;})();
- a function that is never assigned as a property of any object.
- if its owner is (and therefore the function is called as a
member of) only the Variable Object of the execution context
(the Global Object for globally declared functions, and
built-in top-level functions such as Number(); see ES3 Final,
subsection 10.1.5).
So is that supposed to paraphrase as: every function is a method in
ECMAScript implementations - if its owner is only the Variable Object of
the execution context? Because that does not rally make sense.
However, to distinguish between constructors and methods is
typically VK again; every constructor is a function, hence
it is also a method.
No, the 'every function is a method' part of that is not true.
However, taking an overly tolerant attitude towards the meaning of
'method', where any function that is in some sense a property of an
(any) object just acts to render the term redundant, as we can say
'function' in its place and be expressing no less.
'Method' really needs to be used and understood in its object-oriented
sense, where a method is a member of an object. However, in javascript a
function being a member of an object is not sufficient; the function's
relationship with the object is not significantly influenced by its
being just a member of the object, it is how the function is called that
gives a function the special relationship with the object to the extent
that it would be meaningful to call it a 'method'. In short the
categorisation 'method' only meaningfully applies to functions in which
the - this - keyword can be used to refer to the object on which the
function is a member.
This means that the telling discriminator between a function and a
method should be in section 11.2.3; and only circumstances where the -
MemberExpression - resulted in a Reference type that had a non-null base
object that is not an activation object (the global object is never an
activation object), and so will result in a non-null value being passed
into the [[Call]] as the - this - value, would justify labelling a
function a 'method'. For practical purposes the sub-category of
functions that could be labelled 'methods' would be those intended to be
called in this way, otherwise the distinction is meaningless and the
term 'method' is redundant.
Richard.