471,119 Members | 1,205 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

class libraries

it there as way to build class library's of functions and stuff that can be
used in javascript likein vb.net or c#

WStoreyII
Jul 23 '05 #1
2 1061
JavaScript does not really have classes, but yes, you can include
external javascript files:

<script language="JavaScript" src="myexternal.js"></script>

Note that this can only be done in HTML.

WStoreyII wrote:
it there as way to build class library's of functions and stuff that can be
used in javascript likein vb.net or c#

WStoreyII


Jul 23 '05 #2
WStoreyII wrote:
it there as way to build class library's of functions and stuff that can be
used in javascript likein vb.net or c#

WStoreyII


Sure. Create your objects with their associated methods and properties, put
them in a .js file and include them on your page with:

<head>
<!-- other stuff -->
<script type="text/javascript" src="MyDictionary.js"></script>
</head>

Then in MyDictionary.js you might have:

function MyDictionary() {
this.RemoveAll();
}
MyDictionary.prototype.RemoveAll = function() {
this.obj = {};
this.Count = 0;
}
MyDictionary.prototype.Add = function(key, value) {
if (this.obj[key] != null) {
return null;
}
this.obj[key] = value;
this.Count++;
return value;
}
MyDictionary.prototype.Exists = function(key) {
return (this.obj[key] != null);
}
// etc

And you could use it in your page like this:

<script type="text/javascript">
var y = new MyDictionary();
y.Add ("a", "test");
if (y.Exists("a")) {
document.write("a exists in MyDictionary");
}
</script>

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by TF | last post: by
1 post views Thread by rinku24 | last post: by
1 post views Thread by Jim Heavey | last post: by
10 posts views Thread by 4MLA1FN | last post: by
3 posts views Thread by Fernando Chilvarguer | last post: by
4 posts views Thread by Richard | last post: by
3 posts views Thread by djbaker | last post: by

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.