473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Firefox JS vs ECMA - am I missing something?

Q for the language lawyers!
Here's the code:

function f(p)
{
alert("f("+p+") with this="+this);
}

var a = [f];

a[0]("index");
-----------------------------
Shouldn't a[0]("index") invoke f with this===a, since a is the 'base'
of the reference a[0]?
It doesn't, it invokes f with (apparently) this===f.

whereas
var b = new Object;
b.m = f;
b.m("method");

invokes f with this===b.

I seem to be about 3 years late asking a question like this, but I'm
writing this Javascript compiler...
Mar 2 '08 #1
2 1177
Spike wrote:
Q for the language lawyers!
Here's the code:
function f(p)
{
alert("f("+p+") with this="+this);
}
var a = [f];
a[0]("index");

-----------------------------
Shouldn't a[0]("index") invoke f with this===a, since a is the 'base'
of the reference a[0]?
No. Why are you expecting it to use the base. In the call a[0]() it's
a[0] that represents this.
It doesn't, it invokes f with (apparently) this===f.
Same thing. a[0]===f
whereas
var b = new Object;
b.m = f;
b.m("method");

invokes f with this===b.
Same thing again. The object you're referencing here is b, so b is this.
Mar 2 '08 #2
On Sun, 2 Mar 2008 at 02:38:53, in comp.lang.javascript, Spike wrote:
>Q for the language lawyers!
Here's the code:

function f(p)
{
alert("f("+p+") with this="+this);
}

var a = [f];

a[0]("index");
-----------------------------
Shouldn't a[0]("index") invoke f with this===a,
<snip>
If you did

var z = a[0];
z.("index");

what do you think the 'this' value will be while the function is
executing ? Why would it be different when you do

a[0]("index");

instead ?

Remember that the 'this' value is calculated by the execution engine. It
uses a very simple rule and knows nothing about the complications in
your source code.

John
--
John Harris
Mar 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Derek | last post by:
I have the following script in a page and it gets an error in IE 6. Says something about an invalid argument but the line number doesn't help since I can't see the javascript code when viewing...
6
by: Christopher Benson-Manica | last post by:
Is Firefox 1.0.1 within its rights to crash when presented with the following script? <html> <head> <script> var foo="foo"; window.onerror=function( msg, url, line ) { switch( msg ) {...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
5
by: hibernate | last post by:
I'm somewhat new to javascript/DHTML, and this problem has been plaguing me. I have made an 'array' of <div> tags within my html document like so: <div id="menu"> menu1 </div> <div id="menu">...
13
by: bgbauer70 | last post by:
My appologies if this ends up being a duplicate post. For some reason the first post never showed up. I've tried about 300 iterrations of this same ability, and none of them seem to work in...
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
5
by: Don Kim | last post by:
I copied this example off ECMA C++/CLI draft document, and it doesn't compile: #using <mscorlib.dll> using namespace System; public ref class Stack { public: Stack() { first = nullptr;
12
by: VK | last post by:
http://www.mozilla.com
10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
5
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.