Javascript 的用途是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3497115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:54:40  来源:igfitidea点击:

What is the Use of Javascript

javascripthtmldwr

提问by Gladiator

What is the main motto of using Javascript mostly. How it will be useful for developing Applications. I know Html. How it will help me in learning Javascript. Any relations to both JS and html.

主要使用 Javascript 的主要座右铭是什么。它将如何用于开发应用程序。我知道HTML。它将如何帮助我学习 Javascript。与 JS 和 html 的任何关系。

回答by Jay

The main use of Javascript is that it allows you to make things happen in the user's browser without sending messages back and forth to the server. There are a variety of reasons why you might want to do this.

Javascript 的主要用途是它允许您在用户的浏览器中进行操作,而无需向服务器来回发送消息。您可能想要这样做的原因有多种。

For example, sending a message to the server and getting a reply is a relatively long process: it is almost always a noticable time lag, and can take many seconds. Doing something directly in the browser can be much faster. So if, for example, you want to give the user an "invalid data" message of some sort, it can be much faster if it comes from Javascript.

例如,向服务器发送消息并获得回复是一个相对较长的过程:它几乎总是有明显的时间延迟,可能需要很多秒。直接在浏览器中做一些事情会快得多。因此,例如,如果您想向用户提供某种“无效数据”消息,如果它来自 Javascript,它会快得多。

In the same vein, with Javascript you can validate field-by-field rather than waiting until the user has completely filled out the screen and clicked a submit button. For example, suppose you present the user with a screen where he's supposed to enter transaction dates and monetary amounts. The user enters a whole screen full of these -- maybe 20 or 30 transactions -- and then clicks submit. If the user attempts to type dates in a format that you don't recognize, say typing day/month/year when you expected year-month-day, then with Javascript you could give him an error on the first unrecognizable date. With a round trip to the server, he'd have typed in a whole screen-full of invalid dates before you tell him he's doing it wrong.

同样,使用 Javascript,您可以逐个字段验证,而不是等到用户完全填写屏幕并单击提交按钮。例如,假设您向用户展示了一个屏幕,他应该在其中输入交易日期和货币金额。用户进入一整个屏幕——可能是 20 或 30 个交易——然后点击提交。如果用户尝试以您无法识别的格式输入日期,例如在您预期的年-月-日时输入日/月/年,那么使用 Javascript 您可能会在第一个无法识别的日期给他一个错误。通过往返服务器,在你告诉他他做错了之前,他会在整个屏幕上输入一整个无效的日期。

Similarly, trying to do animation with round trips to the server would be unlikely to work, it would be way too slow. One way to do it would be with Javascript. (There are other ways, of course.)

同样,尝试通过往返服务器来制作动画不太可能奏效,它太慢了。一种方法是使用 Javascript。(当然还有其他方法。)

回答by Justin Niessner

Javascript can be used for a multitude of different things.

Javascript 可用于多种不同的事情。

When used alongside HTML in the browser, it can add some really cool dynamic and interactive features (compared with the historically static nature of HTML).

当在浏览器中与 HTML 一起使用时,它可以添加一些非常酷的动态和交互功能(与 HTML 的历史静态特性相比)。

When used alongside a server-side engine like Node.JS, it can do just about anything any other server-side language is capable of.

当与 Node.JS 等服务器端引擎一起使用时,它几乎可以做任何其他服务器端语言能够做的事情。

回答by Crayon Violent

javascript enables you to take your static html and add/make changes to it live on in the browser. Probably the main things to consider with javascript is: do not trust it for validating things, and build it in as a feature, not a requirement for making your site function (In other words, your site should still be able to function if the user has it disabled).

javascript 使您能够获取静态 html 并在浏览器中对其进行添加/更改。使用 javascript 可能需要考虑的主要事项是:不要相信它会验证事物,并将其构建为一项功能,而不是使您的网站正常运行的要求(换句话说,如果用户是否已禁用)。

回答by jcolebrand

http://en.wikipedia.org/wiki/Javascript

http://en.wikipedia.org/wiki/Javascript

  • Blatantly ripping them off...
  • 公然撕毁他们...

JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within a host environment. It can be characterized as a prototype-based object-oriented scripting language that is dynamic, weakly typed and has first-class functions. It is also considered a functional programming language like Scheme and OCaml because it has closures and supports higher-order functions.

JavaScript 是 ECMAScript 语言标准的实现,通常用于启用对主机环境中计算对象的编程访问。它可以被描述为一种基于原型的面向对象的脚本语言,它是动态的、弱类型的并且具有一流的功能。它也被认为是一种类似于 Scheme 和 OCaml 的函数式编程语言,因为它具有闭包并支持高阶函数。

JavaScript is primarily used in the form of client-side JavaScript, implemented as part of a web browser in order to provide enhanced user interfaces and dynamic websites. However, its use in applications outside web pages is also significant.

JavaScript 主要以客户端 JavaScript 的形式使用,作为 Web 浏览器的一部分实现,以提供增强的用户界面和动态网站。但是,它在网页以外的应用程序中的使用也很重要。



It should also be noted: there is no "main motto in JavaScript" as it's a standard, not a project. For projects, check out jQueryas being the one most frequently adopted by developers on this site. There are a great many toolkitsfor working with JavaScript.

还应该注意:没有“JavaScript 的主要座右铭”,因为它是一个标准,而不是一个项目。对于项目,请查看jQuery作为该站点上开发人员最常采用的一种。有很多用于处理 JavaScript 的工具包

The main consideration when working with JavaScript is to understand that it is usually used hand-in-hand with the Document Object Modeland so therefore this is where you will find most people offering ways to use JavaScript. However, it is a fully functional language, and there are ways to compile it to native machine code. An example of how this is possible is by noting that most browsers implement a just-in-time compiler for JavaScript. These JIT compilers convert the JavaScript to native bytecode for execution on the host system.

使用 JavaScript 时的主要考虑是要了解它通常与文档对象模型一起使用,因此您会发现大多数人提供了使用 JavaScript 的方法。但是,它是一种功能齐全的语言,可以通过多种方式将其编译为本地机器代码。注意到大多数浏览器为 JavaScript 实现了即时编译器,这是如何实现的一个示例。这些 JIT 编译器将 JavaScript 转换为本地字节码,以便在主机系统上执行。



Why would you use JavaScript? You could use it for such purposes as client-side validation of form elements (one of the most common), user interaction (drag and drop in a browser window, insert new form elements like textboxes for adding new records to a table), user notification (Facebook notifications), asynchronously retrieving data from a server and loading it into the page (AJAX), or a long list of other possible operations. To list every feature of what JavaScript could be used for here would be a heroic effort.

为什么要使用 JavaScript?您可以将其用于表单元素的客户端验证(最常见的一种)、用户交互(在浏览器窗口中拖放、插入新的表单元素(如文本框以向表中添加新记录)、用户通知(Facebook 通知)、从服务器异步检索数据并将其加载到页面 (AJAX),或一长串其他可能的操作。在这里列出 JavaScript 可用于的所有功能将是一项英勇的努力。

Since it is a prototype language, one can write C style programs in JavaScript.

由于它是一种原型语言,因此可以用 JavaScript 编写 C 风格的程序。

Since it is a functional language, one can write Lisp style programs in JavaScript.

由于它是一种函数式语言,因此可以用 JavaScript 编写 Lisp 风格的程序。

If you've had any formal training in Computer Science then those two languages may be familiar to you. The majority of computer programs are written in either of those two styles. Since JavaScript allows a developer to write in the style with which he is the most fluent, this can be shown to be a boon as the developer is able to start writing code faster on introduction to the language.

如果您接受过任何正式的计算机科学培训,那么您可能熟悉这两种语言。大多数计算机程序都是以这两种风格中的任何一种编写的。由于 JavaScript 允许开发人员以他最流利的风格进行编写,因此这可以证明是一个福音,因为开发人员能够在介绍该语言时更快地开始编写代码。

I have seen full fledged games replete with complicated graphics written in JavaScript. I have also seen rudimentary video players (relying on HTML5) with some basic manipulation functionality written in JavaScript.

我见过成熟的游戏充满了用 JavaScript 编写的复杂图形。我还见过一些基本的操作功能用 JavaScript 编写的基本视频播放器(依赖于 HTML5)。



However, JavaScript being most often used in web applications, it's important to remember that JavaScript is used as a client-side language. It does not affect operations on the server. It can be bypassed. Do not rely on JavaScript to do EVERYTHING for your application.

然而,JavaScript 最常用于 Web 应用程序,重要的是要记住 JavaScript 被用作客户端语言。它不影响服务器上的操作。它可以被绕过。不要依赖 JavaScript 为您的应用程序做所有事情。



Hopefully this helps and gives you some guidance and answers your question?

希望这会有所帮助并为您提供一些指导并回答您的问题?

回答by edtechdev

In web development there are 3 main components: HTML, CSS, and Javascript.

在 Web 开发中,有 3 个主要组件:HTML、CSS 和 Javascript。

HTML is for holding the data, the content, the structure of your webpage or webapp.

HTML 用于保存网页或 web 应用程序的数据、内容和结构。

CSS is for the style, layout, and visual look of your webpage or webapp.

CSS 用于您的网页或 web 应用程序的样式、布局和视觉外观。

And Javascript is (often) for the dynamic or reactive aspects of your webpage or web app: animations, form validation, ajax, and so forth.

Javascript(通常)用于您的网页或 Web 应用程序的动态或反应性方面:动画、表单验证、ajax 等等。

回答by Zango

Nowadays JavaScript is for killing desktop applications!!!
For example ExtJsis perfect library for it.

现在 JavaScript 是用来杀死桌面应用程序的!!!
例如ExtJs是它的完美库。

回答by FrustratedWithFormsDesigner

JavaScript is a language that is executed by web browsers and is often used to make dynamic web pages. A simple example would be if you wish to perform some simple calculations (such as shipping costs) on values that a user puts in a form. You could make the user posts data to the server every time they want an answer, or you could have a button the execute a JavaScript calculation and display the answer to the user. There are more complex examples, of course. AJAX is a currently popular application of JavaScript.

JavaScript 是一种由 Web 浏览器执行的语言,通常用于制作动态网页。一个简单的例子是,如果您希望对用户输入表单的值执行一些简单的计算(例如运输成本)。您可以让用户在每次需要答案时将数据发布到服务器,或者您可以使用一个按钮来执行 JavaScript 计算并向用户显示答案。当然,还有更复杂的例子。AJAX 是当前流行的 JavaScript 应用程序。

回答by devmake

You can use javascript to make your pages more interactive. You can check stuff before sending it server and save time for the user. You can create a lot of interesting stuff with that... there are many web applications relying on javascript as their main engine.

您可以使用 javascript 使您的页面更具交互性。您可以在发送服务器之前检查内容并为用户节省时间。你可以用它创建很多有趣的东西……有很多 web 应用程序依赖于 javascript 作为它们的主要引擎。

回答by Roger

You can use Javascript to development client side "things" in your application. This saves you from going back to the server, which is good for: lower band usage, lower server strength usage and better client user experience. A popular framework is jquery.

您可以使用 Javascript 在您的应用程序中开发客户端“事物”。这使您无需返回服务器,这有利于:较低的带宽使用率、较低的服务器强度使用率和更好的客户端用户体验。一个流行的框架是 jquery。

回答by dkinzer

It's a scripting language that can be used to build dynamic pages but most importantly, it shifts some of the computational effort of running these applications from the server to the client machine.

它是一种脚本语言,可用于构建动态页面,但最重要的是,它将运行这些应用程序的一些计算工作从服务器转移到客户端机器上。

JavaScript is pretty powerful, so it would be difficult to list everything that can be done with it. I wouldn't know what Web 2.0 would look like without it.

JavaScript 非常强大,因此很难列出可以用它完成的所有事情。如果没有它,我不知道 Web 2.0 会是什么样子。

JavaScript is becoming very mainstream these days. There has been a lot of effort put in by Google to make Javascript fast in the V8 JavaScript Engine. Which has led to a lot of interest in serverside JavaScript use.

如今,JavaScript 正变得非常主流。Google 付出了很多努力来使V8 JavaScript 引擎中的 Javascript 更快。这引起了对服务器端 JavaScript 使用的极大兴趣。

NodeJsis a good example of a server-side application that is now growing in popularity with a lot of promise in use cases where asynchronous and functional programming makes sense (like networking applications).

NodeJs是服务器端应用程序的一个很好的例子,它现在越来越受欢迎,在异步和函数式编程有意义的用例(如网络应用程序)中有很多承诺。

Other applications like PhantomJsa headless browser based on WebKit are natural choices when building javascript testing applications or automatic web-scrapers. (CasperJsis a great example of a project built on top of PhantomJs).

其他应用程序,如基于 WebKit 的无头浏览器PhantomJs,是构建 javascript 测试应用程序或自动网络抓取工具时的自然选择。(CasperJs是建立在 PhantomJs 之上的项目的一个很好的例子)。

JavaScript is conceptually more difficult than other languages people come across because it is prototypical as well as functional. Although it is possible to design applications using some of the standard patterns that have been built over the years, there are many ways to implement the exact same patterns and there is no standardization of best practice or consenses on the best way to implement these design.

JavaScript 在概念上比人们遇到的其他语言更难,因为它既是原型又是功能性的。虽然可以使用一些多年来构建的标准模式来设计应用程序,但有很多方法可以实现完全相同的模式,并且没有最佳实践的标准化或对实现这些设计的最佳方法的共识。

There are now many tools that CofeeScriptand TypeScriptthat help close that gap by allowing developers to code in an object oriented language that compiles to a standard object oriented subset of JavaScript.

现在有许多CofeeScriptTypeScript工具通过允许开发人员使用面向对象语言进行编码,编译为 JavaScript 的标准面向对象子集,从而帮助缩小这一差距。