简体   繁体   English

javascript API?

[英]javascript APIs?

I am currently studying Javascript and I was wondering if there are any APIS in it? 我目前正在学习Javascript,想知道其中是否包含APIS? in java we have java.awt.JFrame etc, in C# we have System.Console and etc. in javascript are there any apis? 在Java中,我们有java.awt.JFrame等,在C#中,我们有System.Console等。在javascript中,是否有任何API? or what do you call those libraries in javascript? 或在javascript中如何称呼那些库?

System and java.awt are namespaces. Systemjava.awt是名称空间。 You can create namespaces (of a sort) in JavaScript; 您可以在JavaScript中创建 (某种) 命名空间 by default, every type belongs to the global namespace. 默认情况下,每种类型都属于全局名称空间。

There are a handful of intrinsic objects in the global namespace such as Date and Array . 全局名称空间中有一些内部对象,例如DateArray These objects are instantiable and expose various methods. 这些对象是可实例化的,并公开了各种方法。 Math behaves more like a singleton/static type. Math行为更像是单例/静态类型。 Document and Window are available within a web browser and are not directly instantiable, though there can be multiple instances in use at a single time (parent and child window, for example). 尽管可以一次使用多个实例(例如,父窗口和子窗口),但是DocumentWindow可在Web浏览器中使用,并且不能直接实例化。 Collectively, these form a limited API. 这些共同构成了受限的API。

Global objects from Mozilla 来自Mozilla的全局对象

More on intrinsic objects from Microsoft (there are proprietary items in the list). 有关Microsoft内部对象的更多信息 (列表中有专有项)。

Many developers build elaborate namespace and class structures to form APIs in JavaScript. 许多开发人员构建了精心设计的名称空间和类结构,以在JavaScript中形成API。 Check out Google Charts for a great example (note word "API" right in the URL). 请查看Google图表以获取一个很好的示例(网址中的单词“ API”正确注释)。

Here is the instantiation of a namespaced type: 这是命名空间类型的实例化:

var chart = new google.visualization.PieChart(foo);
chart.draw(data, options);

Here is the loading of a "package": 这是“包”的加载:

google.load('visualization', '1.0', {'packages':['corechart']});

This is a good resource for learning the basic API: https://developer.mozilla.org/en/JavaScript/Reference 这是学习基本API的好资源: https : //developer.mozilla.org/en/JavaScript/Reference

Other than the core components of the language, the APIs (or libraries) available depend on what APIs (or libraries) that you yourself decide to include, and on which environment you are running JavaScript. 除了语言的核心组件之外,可用的API(或库)取决于您自己决定要包括的API(或库)以及运行JavaScript的环境。

If you run JavaScript in the browser you automatically have access to Document Object Model APIs for example. 如果在浏览器中运行JavaScript,则可以自动访问例如文档对象模型API。 If you run in another virtual machine such as Node.js - you will have access to networking APIs. 如果您在其他虚拟机(例如Node.js)中运行-您将有权访问网络API。

But mostly, you will yourself find libraries that you want to use, and include them yourself. 但是大多数情况下,您将自己找到要使用的库,并自己包含它们。

Yes. 是。 And no. 和不。

JavaScript as it runs in the browser has certain global functions and gobal objects which have methods. 在浏览器中运行的JavaScript具有某些全局功能和具有方法的gobal对象。

The most obvious of these is the DOM (Document Object Model) which represents the web page loaded in the browser. 其中最明显的是DOM(文档对象模型),它表示浏览器中加载的网页。

But there are also string functions, etc. 但是也有字符串函数等。

Now if JavaScript is not hosted in a browser, such as node.js for instance, you will not have the DOM, but I'm not sure which if any of the global functions are defined to be part of JavaScript and which are part of the browser implementations. 现在,如果JavaScript未托管在浏览器中(例如,例如node.js ,您将没有DOM,但是我不确定哪个全局函数定义为JavaScript的一部分,以及哪些是全局函数的一部分。浏览器的实现。

Here's something to get you started on the global functions from w3schools.com . 这是从w3schools.com开始使用全局功能的一些方法。

Javascript is a scripting language that runs on web browsers. Javascript是一种可在网络浏览器上运行的脚本语言。 So you can call the browser API with Javascripts. 因此,您可以使用Javascript调用浏览器API。 As an example you can see the google chrome API here , that can be invoked by Javascripts. 作为示例,您可以在此处看到google chrome API,可以通过Javascript调用。

As well as some web applications provide an API for Javascripts like this(Google Maps API) . 某些Web应用程序还为Javascript提供了这样的API (Google Maps API)

If you want a library of Javascripts check Jquery and Jqueryui 如果要使用Javascript库,请检查JqueryJqueryui

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM