From: Thomas Allen on
What is the purpose of canCall in My Library (hereafter and forever ML
so as not to imply that this is mine)? Specifically, I am thinking of
the following code:

var canCall = !!Function.prototype.call;
// ...
if (canCall) {
forEachProperty = function(o, fn, context) {
//...

Why does the presence of Function.prototype.call matter, when
Function.prototype.apply can do the same thing? I ask because if
there's a difference, I'd be very interested as I equate the two in
behavior, apart from their different call styles (making me think of
call as more limited).

Thomas
From: Thomas Allen on
Related, and equally perplexing to me, is the following code:

Updater.prototype.dispatch = function(sEvent, args) {
Requester.prototype.dispatch.apply(this, sEvent, args);

Is the first argument to that apply call intended, when apply (to the
best of my knowledge) only accepts two arguments?

Thomas

On Apr 14, 5:46 pm, Thomas Allen <thomasmal...(a)gmail.com> wrote:
> What is the purpose of canCall in My Library (hereafter and forever ML
> so as not to imply that this is mine)? Specifically, I am thinking of
> the following code:
>
> var canCall = !!Function.prototype.call;
> // ...
> if (canCall) {
>   forEachProperty = function(o, fn, context) {
>     //...
>
> Why does the presence of Function.prototype.call matter, when
> Function.prototype.apply can do the same thing? I ask because if
> there's a difference, I'd be very interested as I equate the two in
> behavior, apart from their different call styles (making me think of
> call as more limited).
>
> Thomas

From: Thomas 'PointedEars' Lahn on
Thomas Allen wrote:

> What is the purpose of canCall in My Library (hereafter and forever ML
> so as not to imply that this is mine)? Specifically, I am thinking of
> the following code:
>
> var canCall = !!Function.prototype.call;
> // ...
> if (canCall) {
> forEachProperty = function(o, fn, context) {
> //...
>
> Why does the presence of Function.prototype.call matter, when
> Function.prototype.apply can do the same thing

The methods cannot really do the same thing (else one method would be
superfluous). The Matrix so far suggests that both methods have the same
compatibility level.

> I ask because if there's a difference, I'd be very interested as I equate
> the two in behavior, apart from their different call styles

However, I would not feature-test Function.prototype.call() and then call
Function.prototype.apply(), and vice-versa. The rule of thumb for feature-
testing is: Always test exactly what you are using later. (Perhaps there
is also a canApply in My Library?)

> (making me think of call as more limited).

It is not as flexible as apply(), but it is probably more efficient to use
if you know the (number of) arguments to be passed to the method so
invoked.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
From: Thomas 'PointedEars' Lahn on
Thomas Allen wrote:

> Related, and equally perplexing to me, is the following code:
>
> Updater.prototype.dispatch = function(sEvent, args) {
> Requester.prototype.dispatch.apply(this, sEvent, args);
>
> Is the first argument to that apply call intended, when apply (to the
> best of my knowledge) only accepts two arguments?

Looks like a refactoring bug and should probably be either

Updater.prototype.dispatch = function(sEvent, args) {
Requester.prototype.dispatch.call(this, sEvent, args);
// ...
};

or

Updater.prototype.dispatch = function(sEvent, args) {
Requester.prototype.dispatch.apply(this, arguments);
// ...
};

or

Updater.prototype.dispatch = function(sEvent, args) {
Requester.prototype.dispatch.apply(this, args);
// ...
};

Please learn to quote properly.

<http://jibbering.com/faq/#posting> pp.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Thomas Allen on
On Apr 14, 6:32 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> Please learn to quote properly.

To quote what, exactly?

Thomas