我现在正在考虑用 JavaScript 建立我的服务器端代码,并开始在上面做所有事情,但我想知道它与 PHP 相比的安全性和灵活性。
我也想知道,它是否可以像 PHP 那样成功地用于开发论坛板、完整的网站和类似的东西。
我现在正在考虑用 JavaScript 建立我的服务器端代码,并开始在上面做所有事情,但我想知道它与 PHP 相比的安全性和灵活性。
我也想知道,它是否可以像 PHP 那样成功地用于开发论坛板、完整的网站和类似的东西。
The question is very, very broad. Interpreting it as "can I use Javascript on the server":
Fundamentally, sure, Javascript is a very powerful language and so you can do development in it server-side just like you can client-side (and if you do client-side scripting as well, you get some definite reuse benefits using Javascript on the server).
Etc. etc. etc. There's quite a list on Wikipedia.
Arguing against, there's a very rich ecosystem built around PHP. Unless you're using something like Rhino for the Java platform or JScript on IIS (because of the ecosystems they leverage), you may find that you don't have nearly that ecosystem available to you when developing in Javascript for the server. I mean, if you're looking for pre-built forum or wiki software (for example), let's just say you can't swing a dead cat without finding one based on PHP, and the same cannot be said of Javascript on the server.
The way they are usually used, PHP and JavaScript run in entirely different worlds, and are not really comparable. (There is a server-side version of JavaScript but it's fair to say it's not especially widespread yet, and doesn't run on standard web hosting.)
The security issues you are going to encounter in JavaScript (on the browser) side are very different from what you have to look out for in PHP.
I want to know too, if it can be sucessfully used to develop things like forum boards, full web-sites and things like this, as PHP does.
No, not with client-side Javascript. For dynamic applications, you will always need some server-side language backing it, be it PHP or some other language like ASP, Python, Ruby, Perl....
要将 PHP 替换为 Javascript,您需要服务器端 Javascript,并且在这方面发生了很多事情。Mozilla 的Rhino在 JVM 上运行 Javascript,而且 Google 似乎也在开发自己的服务器端 Javascript 框架。最流行的生产实现是:
Aptana 的 Jaxer 表现出了很大的希望,尤其是通过将 DOM 带到服务器端,但该项目现在似乎已经死了。据我了解,node.js 不是与 Helma 和 Phobos 相同的服务器端 Javascript 框架。相反,它可以用于用 Javascript 编写事件驱动的服务器(例如:编写自己的 Web 服务器)。
这有点离题,但它实际上可能触及您问题的核心:
如果您只想将一种语言用于 Web 应用程序,您可能想看看Haxe。
它是一种跨平台语言,(在其他目标中)编译为 JavaScript 和 PHP 源代码以及 NekoVM 字节码。对于服务器端 JavaScript,有 NodeJS 绑定。
这样,您就不会绑定到特定平台。neko 和 PHP API 在很大程度上兼容,因此您可以在两个平台上进行部署,可以选择 neko 的速度和持久性或 PHP 的易于部署。但是请注意,PHP 输出有一点开销,尽管常见的优化器作为加速器会使这几乎不引人注意。
Haxe 的宽容度明显低于 JavaScript 和 PHP。这使得它更难学习,但却是一个更安全、更强大且最终更高效的工具。
In a word: no. Javascript is a client-side language. In order to do the things that you are describing, you need a server-side language such as PHP.
EDIT: OK, technically it is possible to implement Javascript in other areas besides the browser, but this is not very common.
5 YEAR EDIT: Well, 5 years later, this answer obviously is not accurate, with the popularity of things like node.js. Let that be a testament to how quickly things can change!
PHP and JavaScript are two different languages that do two different things. One cannot replace the other. You are most likely going to use a combination of the two. JavaScript for client-side stuff. PHP for server-side stuff.