在C ++应用程序中使用JavaScript
When Google released its Chrome browser, the company included a fast implementation of JavaScript called V8, the client-side scripting language included in all browsers. Early adopters of JavaScript back in the era of Netscape 4.1 didn't like the language because there were no tools for debugging and each browser had different implementations, and different versions of Netscape browsers differed as well. It wasn't pleasant writing cross-browser code and testing it on lots of different browsers.
Google发布Chrome浏览器时,该公司包含了一种称为V8JavaScript的快速实现,该JavaScript是所有浏览器中包含的客户端脚本语言。 在Netscape 4.1时代,JavaScript的早期采用者不喜欢该语言,因为没有调试工具,并且每个浏览器都有不同的实现,并且不同版本的Netscape浏览器也有所不同。 编写跨浏览器的代码并在许多不同的浏览器上对其进行测试并不是一件令人愉快的事情。
Since then, Google Maps and Gmail came along using the whole Ajax (Asynchronous JavaScript and XML) technologies, and JavaScript had enjoyed a major comeback. There are now decent tools for it. Google's V8, which is written in C++, compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs. V8 is so much faster than the JavaScript in other browsers because it compiles to native machine code, not bytecode that has been interpreted.
从那时起,Google Maps和Gmail便使用了整个Ajax(异步JavaScript和XML )技术,并且JavaScript经历了一次重大的复兴。 现在有不错的工具。 Google的V8是用C ++编写的,可编译和执行JavaScript源代码,处理对象的内存分配,并垃圾收集不再需要的对象。 V8比其他浏览器中JavaScript快得多,因为它可以编译为本地机器代码,而不是已解释的字节码 。
JavaScript V8V8 isn't only for use with Chrome. If your C++ application requires scripting for users to be able to write code that executes at run-time, then you can embed V8 in your application. V8 is an open source high-performance JavaScript engine licensed under the liberal BSD license. Google has even provided an embedder's guide.
JavaScript V8V8不仅适用于Chrome。 如果您的C ++应用程序要求脚本使用户能够编写在运行时执行的代码,则可以在应用程序中嵌入V8。 V8是在开放BSD许可下获得许可的开源高性能JavaScript引擎。 Google甚至提供了嵌入程序指南 。
Here's a simple example that Google provides—the classic Hello World in JavaScript. It is intended for C++ programmers who want to embed V8 in a C++ application
这是Google提供的一个简单示例-JavaScript中的经典Hello World。 适用于希望将V8嵌入C ++应用程序中的C ++程序员
int main(int argc, char* argv[]) {
// Create a string holding the JavaScript source code.
String source = String::New("'Hello' + ', World'") ;
// Compile it.
Script script = Script::Compile(source) ;
// Run it.
Value result = script->Run() ;
// Convert the result to an ASCII string and display it.
String::AsciiValue ascii(result) ;
printf("%s\n", *ascii) ;
V8 runs as a standalone program, or it can be embedded in any application written in C++.
翻译自: https://www.thoughtco.com/using-javascript-in-your-candand-applications-3971807
上一篇: echo中文是什么意思?
推荐阅读
-
javascript中的toString()方法,在php中有什么一样的函数吗?解决办法
-
可以在JavaScript 里使用PHP连接MySQL吗?
-
JSON进阶第一篇 在PHP与javascript 中使用JSON
-
c - php 扩展中 FREE_ZVAL 和 zval_ptr_dtor 的使用条件?
-
javascript - ajax返回值中,在首位会出现一些莫名其妙的空行
-
在JavaScript中调用php程序_PHP
-
session在PHP大型web应用中的使用
-
php中在PDO中使用事务(Transaction)_PHP
-
使用 Laravel Moderation 扩展在 Laravel 应用中实现简单的内容审核系统
-
在 php 中使用 sockets:从新闻组中获取文章