开发者

Why aren't framework-like functions built in natively?

I was just wondering why trivial functions like String.contains() aren't part of the JavaScript core itself. I mean, although the JavaScript core contains of all functions necessary开发者_运维问答 to create new functions based on the core ones, some obvious functions aren't available by default.

There are some great frameworks out there which basically extend the JavaScript core, but I just don't get why they aren't built in natively.

Also, for instance, the jQuery ajax() function is much more developer-friendly than the native XMLHttpRequest object. It is almost essential to use frameworks for things like this.

So why are functions like these not available in the JavaScript core itself?


There are some great frameworks out there which basically extend the JavaScript core, but I just don't get why they aren't built in natively.

I don't think anyone had the foresight to think 10-15 years in advance and see how the implementations of technologies would play out, in terms of which browsers would support parts of the specifications that were currently standardized at the time to create these utility functions which we find useful in 2011.

Javascript was created in 1995 by Eich and the landscape was far different. "Ajax" didn't exist at that time, so how would anyone think that 15-16 years later we'd need some cross-browser ajax functionality? Microsoft introduced the iframe in 1996 and XMLHttp ( Ajax ) in 1999.

If you were Brendan Eich in 1995, and think about the functionality of browsers and the fact that the Internet wasn't as popular as it is now, and there was a lack of standardization - would you have thought of these things? Many of which, such as "Ajax", didn't even exist?

As far as the language changing, the reason I'd say is primarily because there was a vast amount of time between the IE releases, in particular IE6 to IE7 which was 5-6 years apart and IE7 still had ECMA-262, CSS1/CSS2 bugs so how would it possibly have support for newer Javascript features if they were so slow to adopt specs that were released years prior.

This was mentioned in another answer, but Javascript is just a superset of the original Javascript, ECMAScript. ECMAScript, the core upon which Actionscript and Javascript and other languages are built upon doesn't incorporate a DOM or methods like XMLHttpRequest. The browser binds the scripting language with a rendering engine / DOM and supplies browser methods to the environment.


As with all Why doesn't X language have Y feature? questions the answer is:

Because the original language authors didn't include it.

Why exactly? I guess only they know.


I think it's important to note that JavaScript, aka ECMAScript, isn't necessarily meant to be a browser language. What it's intended to be is an embeddable language that can be used within any program. Things like XMLHttpRequest aren't part of the language, they're just provided by the browser as one way to make the language actually [i]do[/i] something, because pure JavaScript has no built-in operations to interact with anything.

As for String, I'm not sure why so many String operations were left out of the language. For instance, why no Trim function? Who knows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜