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

Discussion in 'ASP General' started by Jonathan Dodds, Mar 17, 2005.

  1. 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.
    Jonathan Dodds, Mar 17, 2005
    #1
    1. Advertising

  2. 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:...
    >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.
    >
    >
    Jason Brown [MSFT], Mar 17, 2005
    #2
    1. Advertising

  3. 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 ,
    "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.
    >
    >
    Aaron [SQL Server MVP], Mar 17, 2005
    #3
  4. 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]" <> wrote in message
    news:...
    > 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:...
    > >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.
    > >
    > >

    >
    >
    Jonathan Dodds, Mar 17, 2005
    #4
  5. Thanks Aaron. That is exactly the problem.

    "Aaron [SQL Server MVP]" <> wrote in message
    news:BE5E62C2.38DD%...
    > 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 ,
    > "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.
    > >
    > >

    >
    Jonathan Dodds, Mar 17, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,247
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,374
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. jaime

    fgets prototype doesn't include const?

    jaime, Aug 13, 2007, in forum: C Programming
    Replies:
    11
    Views:
    676
  4. John Bentley
    Replies:
    14
    Views:
    335
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    346
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page