In JavaScript, almost every js used is inseparable from its objects. Let's take a deeper look at js objects.
The classification of objects in js is the same as the classification of functions in the language we have learned before. One is the predefined object that comes with the system, and the other is the one written by the user himself. object. The general content is as shown below:
##
1: Core Object
Array object, used to create arrays, use new to create
##Common attributes :
Explain the creation and use of Array objects through examples ,as follows.
<script language="javascript"> var data=new Array("1","2","3");//创建数组data document.writeln("data的初始内容为:"+data+","); //输出数组内容 function fun(){ //自定义函数fun()显示数组长度 if(this.length!=0){ document.writeln("<PRE>此数组的长度为:"+this.length+""); }else{ document.writeln("
此数组的长度为0"); } } Array.prototype.fun=fun; //为Array对象添加fun()方法 data.fun(); //调用fun()方法 data=new Array();//清空data数组内容 data.fun();//显示清空后数组的长度
Run result:
##Description:
prototype Used to add new properties and methods, the usage is: Array.prototype.functionName=functionName
##2, Function object
Commonly used attributes are as follows:
The following examples illustrate:
<script language="javascript"> funSum=new Function("x","y","z=x+y;return z"); //创建函数funSum() x=prompt("请输X值:",""); y=prompt("请输Y值:",""); x=Number(x); y=Number(y); alert(newfun(x,y)); //调用函数并输出 </script>Note: Function objects cannot be written as smaller functions. Function is an object, used to dynamically create functions. Function is a keyword. The function obtained through function new is also an instance of the Function object.
##3, String object
String object provides properties and methods for processing strings. When using, you can assign the value directly or create it through new and then assign the value
String对象有很多方法,主要是用户有关字符串在Web页面中的显示格式,字体大小,字体颜色,字符的搜索以及字符的大小写转换方面的功能。
通过以上对象的prototype属性,我们也看到了JavaScript的特点,它不仅提供给我们一些功能,还提供给用户自己添加功能的方法,简直是太好了。
二:文档对象
document对象,接触JavaScript的第一个例子是通过ID名称获取控件的名称,里面就用到document,当时没有多想,就当是关键字过了。
document对象是window对象的属性,也是唯一的即属于BOM又属于DOM的对象。
说到window对象,我们首先来看一下window中各对象间的关系。如下图:
了解了大体结构关系,接下看看看document对象的常用属性:
有关document对象的方法,这里说说使用最频繁的.write()/.writeln()方法。这两个方法的作用都是打印字符,不同的是writeln打印完后多了个换行。
下面写一个用document对象的write方法动态添加JavaScript文件的实例
<script language="javascript"> document.write("<script type=\"text/javascript\" src=\"textuser.js\">"+"</scr"+"ipt>"); </script>
这里主要想说明为什么是分开的。
我们可以先看一下分开写的网页源码:
看不出什么不同,接下来我们看一下不分开时网页源码:
结果很明显,如果不分开写 会和前面的<script>配对,这样,浏览器会提示我们有误。</script>
三:事件对象
event对象是一种只与事件处理过程有关的对象。
JavaScript中的事件跟vb中学过的事件一致,有鼠标事件,键盘事件,加载事件,等。。
事件的发生肯定有其出发者,触发发生后,这一事件也就随即结束。
事件在JavaScript中使用很简单,就是在关键字前加On。
The above is the detailed content of A summary of how to learn JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.