asp.net - How to create a file of constants in Javascript? - Stack Overflow

Is there a way to create a file of constants in JavaScript, which I can reference and then use?What I

Is there a way to create a file of constants in JavaScript, which I can reference and then use? What I am looking for is something like this:
Constants.js:

var Phones =
{
Nokia: 1,
Samsung: 2
}

Then, in another JavaScript file JS2.js access those values: JS2.js:
alert(Phones.Nokia);

And then, in an aspx file that uses them, reference both of them, like:
<asp:ScriptReference Path="../js/JS2.js" />
<asp:ScriptReference Path="../js/Constants.js" />

Is such an architecture possible? What datatypes can we use? I only exemplified enums because this is what i use right now, but they must be declared in the same file as they are used.

Is there a way to create a file of constants in JavaScript, which I can reference and then use? What I am looking for is something like this:
Constants.js:

var Phones =
{
Nokia: 1,
Samsung: 2
}

Then, in another JavaScript file JS2.js access those values: JS2.js:
alert(Phones.Nokia);

And then, in an aspx file that uses them, reference both of them, like:
<asp:ScriptReference Path="../js/JS2.js" />
<asp:ScriptReference Path="../js/Constants.js" />

Is such an architecture possible? What datatypes can we use? I only exemplified enums because this is what i use right now, but they must be declared in the same file as they are used.

Share Improve this question asked Jun 30, 2010 at 19:01 TheRifleTheRifle 711 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

It is very much possible (exactly as you use them). It won't be an enum though, just an object with several numeric fields.

You should use the script reference to constants as the topmost one (logically).

The mon types are:

  • undefined (variable)
  • null (variable)
  • String
  • Boolean
  • Number
  • String
  • Object

you're doing it right.

make sure the constants are declared first.

JavaScript parses alls scripts and script file links in top down order.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745078195a4609961.html

相关推荐

  • asp.net - How to create a file of constants in Javascript? - Stack Overflow

    Is there a way to create a file of constants in JavaScript, which I can reference and then use?What I

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信