Jump to content

JavaScript 2.0


Jesdisciple

Recommended Posts

You can create classes in javascript something like this:

function House(width, length, height) {   this._width = width;   this._length = length;   this._height = height;   this._windows = 0;}House.protoype.createWindow = function() {   this._windows += 1;}

later on you can use this function as a class:myHouse = new House(500,200,30);while(myHouse._windows < 5) { myHouse.createWindow();}I haven't practised much with classes, but I think this is how they're used in javascript.

Link to comment
Share on other sites

Yes, classes have a limited implementation as it is, but this is more like a series of hacks than true support (at least to me). The feature which originally caught my click on Google was the import statement (here); not even a hack can get this for us (unless one writes JavaScript in server-side script files, then includes other, similar JavaScript on the server, which I do, or retrieves those files via AJAX, which I haven't tried yet).

Link to comment
Share on other sites

I guess to simulate "import" you can do this:

function House() {   ...   // some script   ...   /* This will load other JS files relevant to the library */   files = new Array();   files[0] = "JS file URL";   files[1] = "another JS file URL";   files[2] = "another JS file URL";   for(var i = 0;i<files.length;i++) {	  el = document.createElement("script");	  el.src = files[i];	  document.getElementsByTagName("head")[0].appendChild(el);   }}

Link to comment
Share on other sites

Yes, classes have a limited implementation as it is, but this is more like a series of hacks than true support (at least to me).
Yeah, that's how Javascript handles things. Arrays and Objects in Javascript are exactly the same thing. If you do these:
temp['prop1'] = 'val1';temp['prop2'] = 'val2';temp['meth1'] = function () { alert('meth1']; };

temp.prop1 = 'val1';temp.prop2 = 'val2';temp.meth1 = function () { alert('meth1'); };

They will create the exact same structure. You can use the array syntax or dot notation for either of them. You can call the method either way for either object:temp.meth1();temp['meth1']();

Link to comment
Share on other sites

Ingolme, thanks for the robust antithesis; I'll have to try that.justsomeguy, yeah, it's an awfully jerry-rigged language, isn't it? It seems like Sun would have rejected the marketing insult... (I wonder why the proposed repairs were never applied... Oh, well; they weren't.)

Link to comment
Share on other sites

yeah, it's an awfully jerry-rigged language, isn't it?
Well, that is what comes from having many different organisations trying to add to a single language...
Link to comment
Share on other sites

We'd get rid of all this nonsense if we'd just call JS what it really is, EMCAScript. Sure EMCAS doesn't have a nice as a roll for the tongue as JS, but at least then we would not fall for marketing ploy.What I would like to know is whatever happened to E4X. It's an official standard, so I believe. In this new era of Web 2.0, it seems like this would we helpful what with all the AJAX floating on the interweb. Probably because IE won't support it anytime in the future, and it wants to retain its own proprietary XML variable.

Link to comment
Share on other sites

Mozilla has since 1.5 had decent and full support for E4X, that alone should be a sizable group, and you could always detect the browser so you can use specific code for FF. Gecko in general supports it now, so every release of FF and Netscape should do just fine with it. Not quite clear on it, but full E4X support in Opera is supposed to come within the next release. In the end, it should just be Microsoft and its Internet Explorer that don't come to support it. I'd say its pretty safe to use right now, if only for the fact that FF has good ground, at least to play with it.Side note, ActionScript 3.0 has support for it, but I'm not migrating to it anytime soon so I won't be able to judge how that is.

Link to comment
Share on other sites

I have a certainty that most of my visitors use Internet Explorer yet. Until Internet Explorer 8 comes with E4X, better CSS, more standard Javascript (or ECMAscript) and XHTML support, I'll still have to continue adapting my sites for it.

Link to comment
Share on other sites

You're more optimistic than me. Microsoft doesn't conform to standards if they feel it gets in their way. They just make their own and stick to it. Of course that's cynical, but its also true in an extent. Their HTML generator program, whatever the 2007 edition is, makes some code that won't be properly displayed in IE7 if what I've read is true from some users. Maybe in a future where there is competition...Regardless, you shouldn't have to choose E4X or abandon IE7. You could just load up different functions you define depending on the browser it runs in. Since E4X is solely about adding direct XML support into EMCAScript, it doesn't actively add features that would exclude IE outside of XML. In fact, you wouldn't know if you were running E4X or plain vanilla JS unless you checked the code. Like I said, FF provides a good place to test the waters, and the percentages for its use are higher in Europe than in America, ≈ 15% vs 30%+, last time I checked.

Link to comment
Share on other sites

Following up on Ingolme's suggestion, the script tag goes into the head, but is immediately taken out (in Firefox), I guess for security reasons. I'm looking into using synchronous XHR to get the source to be eval()'ed.

Link to comment
Share on other sites

IE7 only implements JavaScript (JScript) 1.2 or 1.3 while Firfox 2 and Opera, etc implement 1.7. Firefox 3 beta is out. I am not sure what is supported in this new version. There is a lot of heated debate in the JS community on whether JS2 is a good thing or not. Once all that OOP stuff is implemented it could make browser scripting really slow on older machines.

Link to comment
Share on other sites

So you're saying JS2 is still in the future? The (Netscape) email address for the man maintaining it has been canceled, and it seems like a dead project.

Link to comment
Share on other sites

The man maintaining it has been canceled, and it seems like a dead project.
I'm not sure there was an overwhelming anticipation to begin with. Probably better off this way, as people seem to be doing fine without it. It doesn't seem to me like something that needs to be updated, aside from what I think E4X could do for JS, I'm content as a developer; plus, I get enough JS errors as is. :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...