473,624 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OO javascript in ASP

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.prototyp e.pi = Math.PI;
Circle.prototyp e.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.
Jul 22 '05 #1
2 1119
the two different script blocks are executed at different times, so it can
cause problems, depending on what it is you're trying to accomplish. I
believe aspfaq.com has an FAQ on this subject which explains it pretty
clearly.

I'm really not sure why it was done this way (the original ASP spec is
pretty old now) but i think it's possible that very early ASP engine code
used one or the other of the conventions and the other was "tacked on"
later. It's an interesting question though, and I'll see what I can find out
on the subject.
--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Dodds" <NO_REPLY> wrote in message
news:uv******** ********@tk2msf tngp13.phx.gbl. ..
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.prototyp e.pi = Math.PI;
Circle.prototyp e.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.

Jul 22 '05 #2
My work-around solution is to create factory functions that wrap both the
real constrctors and the prototype statements.

e.g.

// circle.inc

function makeCircle(xPoi nt, yPoint, radius)
{

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.prototyp e.pi = Math.PI;
Circle.prototyp e.area = function () {
return this.pi * this.r * this.r;
}

var obj = new Circle(xPoint, yPoint, radius);
return obj;
}
"Jason Brown [MSFT]" <i-******@online.m icrosoft.com> wrote in message
news:eJ******** *****@TK2MSFTNG P14.phx.gbl...
the two different script blocks are executed at different times, so it can
cause problems, depending on what it is you're trying to accomplish. I
believe aspfaq.com has an FAQ on this subject which explains it pretty
clearly.

I'm really not sure why it was done this way (the original ASP spec is
pretty old now) but i think it's possible that very early ASP engine code
used one or the other of the conventions and the other was "tacked on"
later. It's an interesting question though, and I'll see what I can find out on the subject.
--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no rights.

"Jonathan Dodds" <NO_REPLY> wrote in message
news:uv******** ********@tk2msf tngp13.phx.gbl. ..
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.prototyp e.pi = Math.PI;
Circle.prototyp e.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.


Jul 22 '05 #3

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

Similar topics

0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7159
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.