为什么这段代码使用JavaScript的.aspx文件?

时间:2022-05-02 15:46:24

I found some old code which I'm not sure I understand completely. The folowing is an .aspx page containing only JavaScript:

我发现了一些我不确定完全理解的旧代码。以下是仅包含JavaScript的.aspx页面:

<%@ Page Language="C#" EnableSessionState="True" CodePage="65001" uiculture="auto" %>

<%
Response.ContentType = "text/plain";
%>


var csBackgroundColor;

function testfx() {
    csBackgroundColor.setAttribute('disabled', 'disabled');
}

and it was referenced like this:

它被引用如下:

<script type="text/javascript" src="filename.js.aspx"></script>

I'm wondering why it wasn't just marked as completely a JavaScript file? Was it done this way so you could include code blocks? With the file this way, I don't even get IntelliSense.

我想知道为什么它不仅仅被标记为完全是一个JavaScript文件?是这样做的,所以你可以包括代码块?使用这种方式的文件,我甚至没有获得IntelliSense。

2 个解决方案

#1


3  

<hack>To get intellisense you could wrap the code in <script> ... </script> blocks and remove them before saving.</hack>

要获得intellisense,您可以将代码包装在

This was probably created by a developer that didn't want to, couldn't, or didn't have the time to write object oriented JavaScript. Encapsulating the logic and configuring through a configuration object would allow you to de-couple the code from external variable dependencies, (e.g. var foo = <%= SomeServerSideVariable %>).

这可能是由一个不想,不能或没有时间编写面向对象的JavaScript的开发人员创建的。通过配置对象封装逻辑和配置将允许您从外部变量依赖项中解除代码(例如var foo = <%= SomeServerSideVariable%>)。

#2


5  

First time I see something like that but you're right, the reason behind this is to make the file to be processed by the asp.net engine and run it as any other aspx page, giving him the chance to use server side code to build the js file.

我第一次看到类似的东西,但你是对的,这背后的原因是让文件由asp.net引擎处理并运行它作为任何其他aspx页面,让他有机会使用服务器端代码构建js文件。

If that's all the code in the file, it seems the only objetive was to set the character encoding (CodePage="65001" and the content type (Response.ContentType="text/plain"). It wouldn't make a lot of sense as you can imagine.

如果这是文件中的所有代码,似乎唯一的目的是设置字符编码(CodePage =“65001”和内容类型(Response.ContentType =“text / plain”)。它不会产生很多你可以想象的感觉。

#1


3  

<hack>To get intellisense you could wrap the code in <script> ... </script> blocks and remove them before saving.</hack>

要获得intellisense,您可以将代码包装在

This was probably created by a developer that didn't want to, couldn't, or didn't have the time to write object oriented JavaScript. Encapsulating the logic and configuring through a configuration object would allow you to de-couple the code from external variable dependencies, (e.g. var foo = <%= SomeServerSideVariable %>).

这可能是由一个不想,不能或没有时间编写面向对象的JavaScript的开发人员创建的。通过配置对象封装逻辑和配置将允许您从外部变量依赖项中解除代码(例如var foo = <%= SomeServerSideVariable%>)。

#2


5  

First time I see something like that but you're right, the reason behind this is to make the file to be processed by the asp.net engine and run it as any other aspx page, giving him the chance to use server side code to build the js file.

我第一次看到类似的东西,但你是对的,这背后的原因是让文件由asp.net引擎处理并运行它作为任何其他aspx页面,让他有机会使用服务器端代码构建js文件。

If that's all the code in the file, it seems the only objetive was to set the character encoding (CodePage="65001" and the content type (Response.ContentType="text/plain"). It wouldn't make a lot of sense as you can imagine.

如果这是文件中的所有代码,似乎唯一的目的是设置字符编码(CodePage =“65001”和内容类型(Response.ContentType =“text / plain”)。它不会产生很多你可以想象的感觉。