473,403 Members | 2,071 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,403 software developers and data experts.

JScript/ASP prototype doesn't work from an include?

I have two files in an ASP project I created with VI 6.0: circle.inc and
default.asp.

circle.inc:

// 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;
}

default.asp:

<%@ language="jscript" %>
<html>
<head>
<script language="javascript" runat="server" src="circle.inc"></script>
</head>
<body>
<%
var aCircle = new Circle(5, 11, 99);
for (var x in aCircle)
{
Response.Write(x + " = " + aCircle[x] + " (" + typeof(aCircle[x]) +
")<br>");
}
%>
</body>
</html>

I expect output that look like this:

area = function () { return this.pi * this.r * this.r; } (function)
pi = 3.141592653589793 (number)
x = 5 (number)
y = 11 (number)
r = 99 (number)

This works when the circle constructor and prototype are in the default.asp
file but when I move the code to the circle.inc include file I lose the
members that are added by the prototype. i.e.:

x = 5 (number)
y = 11 (number)
r = 99 (number)

When I use the include file it finds the constructor but loses the
prototype? What the heck!?

I tried using a #include directive instead of the script element. It made no
difference. I searched the MSDN to see if there was some mention of this
issue. I didn't find anything relevant.

Is this a bug or am I including this file incorrectly?

Thanks.
Jul 22 '05 #1
4 1495
don't use a server-side script block to include the code. use an actual SSI

<!--#include virtual="/path/here.inc"-->

code in <% %> delimiters and code in <script> blocks execute in different
contexts, hence your problem here
--
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:eY**************@TK2MSFTNGP10.phx.gbl...
I have two files in an ASP project I created with VI 6.0: circle.inc and
default.asp.

circle.inc:

// 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;
}

default.asp:

<%@ language="jscript" %>
<html>
<head>
<script language="javascript" runat="server" src="circle.inc"></script>
</head>
<body>
<%
var aCircle = new Circle(5, 11, 99);
for (var x in aCircle)
{
Response.Write(x + " = " + aCircle[x] + " (" + typeof(aCircle[x]) +
")<br>");
}
%>
</body>
</html>

I expect output that look like this:

area = function () { return this.pi * this.r * this.r; } (function)
pi = 3.141592653589793 (number)
x = 5 (number)
y = 11 (number)
r = 99 (number)

This works when the circle constructor and prototype are in the
default.asp
file but when I move the code to the circle.inc include file I lose the
members that are added by the prototype. i.e.:

x = 5 (number)
y = 11 (number)
r = 99 (number)

When I use the include file it finds the constructor but loses the
prototype? What the heck!?

I tried using a #include directive instead of the script element. It made
no
difference. I searched the MSDN to see if there was some mention of this
issue. I didn't find anything relevant.

Is this a bug or am I including this file incorrectly?

Thanks.

Jul 22 '05 #2
I believe you have been bitten by the "order matters" nature of <%%> and
<script> delimiters.

http://www.aspfaq.com/2045

You could try enclosing the inline code with <script> instead of <% or you
could use <% in the .inc file and use a standard <!--#include instead of the
script-tag style.

A
On 3/16/05 9:49 PM, in article eY**************@TK2MSFTNGP10.phx.gbl,
"Jonathan Dodds" <NO_REPLY> wrote:
I have two files in an ASP project I created with VI 6.0: circle.inc and
default.asp.

circle.inc:

// 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;
}

default.asp:

<%@ language="jscript" %>
<html>
<head>
<script language="javascript" runat="server" src="circle.inc"></script>
</head>
<body>
<%
var aCircle = new Circle(5, 11, 99);
for (var x in aCircle)
{
Response.Write(x + " = " + aCircle[x] + " (" + typeof(aCircle[x]) +
")<br>");
}
%>
</body>
</html>

I expect output that look like this:

area = function () { return this.pi * this.r * this.r; } (function)
pi = 3.141592653589793 (number)
x = 5 (number)
y = 11 (number)
r = 99 (number)

This works when the circle constructor and prototype are in the default.asp
file but when I move the code to the circle.inc include file I lose the
members that are added by the prototype. i.e.:

x = 5 (number)
y = 11 (number)
r = 99 (number)

When I use the include file it finds the constructor but loses the
prototype? What the heck!?

I tried using a #include directive instead of the script element. It made no
difference. I searched the MSDN to see if there was some mention of this
issue. I didn't find anything relevant.

Is this a bug or am I including this file incorrectly?

Thanks.


Jul 22 '05 #3
Thanks.

I tried both ways: two <script> blocks and two sets of <% %> blocks. As long
as I match, the code works correctly.
"Jason Brown [MSFT]" <i-******@online.microsoft.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
don't use a server-side script block to include the code. use an actual SSI
<!--#include virtual="/path/here.inc"-->

code in <% %> delimiters and code in <script> blocks execute in different
contexts, hence your problem here
--
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:eY**************@TK2MSFTNGP10.phx.gbl...
I have two files in an ASP project I created with VI 6.0: circle.inc and
default.asp.

circle.inc:

// 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;
}

default.asp:

<%@ language="jscript" %>
<html>
<head>
<script language="javascript" runat="server" src="circle.inc"></script>
</head>
<body>
<%
var aCircle = new Circle(5, 11, 99);
for (var x in aCircle)
{
Response.Write(x + " = " + aCircle[x] + " (" + typeof(aCircle[x]) +
")<br>");
}
%>
</body>
</html>

I expect output that look like this:

area = function () { return this.pi * this.r * this.r; } (function)
pi = 3.141592653589793 (number)
x = 5 (number)
y = 11 (number)
r = 99 (number)

This works when the circle constructor and prototype are in the
default.asp
file but when I move the code to the circle.inc include file I lose the
members that are added by the prototype. i.e.:

x = 5 (number)
y = 11 (number)
r = 99 (number)

When I use the include file it finds the constructor but loses the
prototype? What the heck!?

I tried using a #include directive instead of the script element. It made no
difference. I searched the MSDN to see if there was some mention of this
issue. I didn't find anything relevant.

Is this a bug or am I including this file incorrectly?

Thanks.


Jul 22 '05 #4
Thanks Aaron. That is exactly the problem.

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:BE5E62C2.38DD%te*****@dnartreb.noraa...
I believe you have been bitten by the "order matters" nature of <%%> and
<script> delimiters.

http://www.aspfaq.com/2045

You could try enclosing the inline code with <script> instead of <% or you
could use <% in the .inc file and use a standard <!--#include instead of the script-tag style.

A
On 3/16/05 9:49 PM, in article eY**************@TK2MSFTNGP10.phx.gbl,
"Jonathan Dodds" <NO_REPLY> wrote:
I have two files in an ASP project I created with VI 6.0: circle.inc and
default.asp.

circle.inc:

// 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;
}

default.asp:

<%@ language="jscript" %>
<html>
<head>
<script language="javascript" runat="server" src="circle.inc"></script>
</head>
<body>
<%
var aCircle = new Circle(5, 11, 99);
for (var x in aCircle)
{
Response.Write(x + " = " + aCircle[x] + " (" + typeof(aCircle[x]) +
")<br>");
}
%>
</body>
</html>

I expect output that look like this:

area = function () { return this.pi * this.r * this.r; } (function)
pi = 3.141592653589793 (number)
x = 5 (number)
y = 11 (number)
r = 99 (number)

This works when the circle constructor and prototype are in the default.asp file but when I move the code to the circle.inc include file I lose the
members that are added by the prototype. i.e.:

x = 5 (number)
y = 11 (number)
r = 99 (number)

When I use the include file it finds the constructor but loses the
prototype? What the heck!?

I tried using a #include directive instead of the script element. It made no difference. I searched the MSDN to see if there was some mention of this
issue. I didn't find anything relevant.

Is this a bug or am I including this file incorrectly?

Thanks.

Jul 22 '05 #5

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

Similar topics

20
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
4
by: Harag | last post by:
Hi All I currently thinking of converting from my little knowledge of VBscript to jScript ASP. With this in mind I'm looking at my current code to see how it will convert over to Jscript. ...
2
by: bubbabubbs | last post by:
Platform: Win2K/SP4 I am trying to use an associative array in JScript, but I am seeing something weird. Example: ArrayTest(); /////////////////////////////////////////////////// function...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
37
by: pochartrand | last post by:
Hello, Is there a way to manipulate or at least read the pseudo-class of an element ? I know the style attribute can be accessed and gives the CSS properties for a particular element....
2
by: danny.dion | last post by:
Hi ! I have a question about JScript : I have an object class wich dynamically creates a control in the page. Then it binds an event to that control, pointing on one of its methods (the...
1
by: Eran | last post by:
I am trying to hook up or get some kind of a notification event when the script engine is executing a certain JScript function. The script engine is not hosted in IE, but in an independent...
10
by: jaime | last post by:
Hi all. According to the fgets wikipedia page, its prototype is: char* fgets(char *string, int length, FILE * stream) Given that fgets never assigns to the first parameter (the char...
0
by: zdrakec | last post by:
Hello all: Consider the following class definition in JScript, using ASP.NET AJAX: Type.registerNamespace('Namespace.Subns.SubSubns.ClassName'); // class definition...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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...

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.