J
Jonathan Dodds
In "VBScript and JScript Don't Mix, at least in ASP"
<http://blogs.msdn.com/ericlippert/contact.aspx> Eric Lippert wrote:
Ideally you want the server side <SCRIPT> blocks to contain only global
function definitions, and the <% %> blocks to contain only "inline" code.
Why? Is this a convention or is there a difference between <script> element
blocks and <% %> blocks that make the former better for functions and the
latter better for inline?
I'm trying to use object-oriented JavaScript in my ASP application. I have a
constructor function and some prototype definitions. Here's an example from
the JScript documentation:
// circle.inc
function Circle (xPoint, yPoint, radius) {
this.x = xPoint; // The x component of the center of the circle.
this.y = yPoint; // The y component of the center of the circle.
this.r = radius; // The radius of the circle.
}
Circle.prototype.pi = Math.PI;
Circle.prototype.area = function () {
return this.pi * this.r * this.r;
}
What's not shown in this example is that the prototype can be used to create
an inheritance chain.
If I put this in a file and include it using a script element and my page is
in JScript then the constructor is available in my <% %> blocks but the
prototype assignments are missing (because they haven't been performed yet.)
So I can change to using the SSI style include and change the included file
to be one large <% %> block. This solves the problem for general pages
(unless there's a penalty for having functions in a <% %> block) but now I
can't reuse the same include files from global.asa.
What's the rationale or reason for executing <script> in the page language
and <% %> blocks in separate passes? I can see the issue when mixing
different script languages but when everything is the same language? Why
isn't <script runat="server"> just syntactic sugar for <% %>?
Thanks.
<http://blogs.msdn.com/ericlippert/contact.aspx> Eric Lippert wrote:
Ideally you want the server side <SCRIPT> blocks to contain only global
function definitions, and the <% %> blocks to contain only "inline" code.
Why? Is this a convention or is there a difference between <script> element
blocks and <% %> blocks that make the former better for functions and the
latter better for inline?
I'm trying to use object-oriented JavaScript in my ASP application. I have a
constructor function and some prototype definitions. Here's an example from
the JScript documentation:
// circle.inc
function Circle (xPoint, yPoint, radius) {
this.x = xPoint; // The x component of the center of the circle.
this.y = yPoint; // The y component of the center of the circle.
this.r = radius; // The radius of the circle.
}
Circle.prototype.pi = Math.PI;
Circle.prototype.area = function () {
return this.pi * this.r * this.r;
}
What's not shown in this example is that the prototype can be used to create
an inheritance chain.
If I put this in a file and include it using a script element and my page is
in JScript then the constructor is available in my <% %> blocks but the
prototype assignments are missing (because they haven't been performed yet.)
So I can change to using the SSI style include and change the included file
to be one large <% %> block. This solves the problem for general pages
(unless there's a penalty for having functions in a <% %> block) but now I
can't reuse the same include files from global.asa.
What's the rationale or reason for executing <script> in the page language
and <% %> blocks in separate passes? I can see the issue when mixing
different script languages but when everything is the same language? Why
isn't <script runat="server"> just syntactic sugar for <% %>?
Thanks.