一种面向对象语言需要向开发者提供四种基本能力:
(1) 封装——把相关的信息(无论数据或方法)存储在对象中的能力。
(2) 聚集——把一个对象存储在另一个对象内的能力。
(3) 继承——由另一个类(或多个类)得来类的属性和方法的能力。
(4) 多态——编写能以多种方法运行的函数或方法的能力。
对象的类型
1.本地对象
①Array类
②Date类
2.内置对象
3.宿主对象
Array类
toString()方法和valueOf()方法,返回特殊的字符串。该字符串是通过对每项调用toString()方法,然后用逗号把它们连接在一起构成的。例如,对具有项"red"、"green"和"blue"的数组调用toString()方法或valueOf()方法,返回的是字符串"red,green,blue"。
join()方法唯一的用途就是连接字符串值。join()方法只有一个参数,即数组项之间使用的字符串。
split()方法将字符串转换成数组,split()方法只有一个参数,就是被看作数组项之间的分隔符的字符串。如果把空字符串声明为分隔符,那么split()方法返回的数组中的每个项是字符串的字符。
concat()方法处理数组的方式几乎与它处理字符串的方式完全一样。参数将被附加在数组末尾,返回的函数值是新的Array对象(包括原始数组中的项和新的项)。
slice()方法接受一个或两个参数,即要提取的项的起始位置和结束位置。如果只有一个参数,该方法将返回从该位置开始到数组结尾的所有项;如果有两个参数,该方法将返回第一个位置和第二个位置间的所有项,不包括第二个位置处的项。
unshift()方法,它把一个项放在数组的第一个位置,然后把余下的项向下移动一个位置。
reverse()方法颠倒数组项的顺序。
sort()方法将根据数组项的值按升序为它们排序。(注意:只是对字符串代码的排序,数字数组的排序需要另解)
splice()方法最复杂的方法,把数据项插入数组的中部。
1.删除——只需要声明两个参数,就可以从数组中删除任意多个项,这两个参数是要删除的第一个项的位置和要删除的项的个数。例如arr.splice(0,2)将删除数组arr中的前两项。
2.替换而不删除——声明三个参数就可以把数据项插入指定的位置,这三个参数是起始位置、0(要删除的数组项的个数)和要插入的项。此外,还可以用第四个、第五个或更多个参数指定其他要插入的项。例如,arr.splice(2,0,"red", "green")将在位置2处插入"red"和"green"。
3.替换并删除——声明三个参数就可以把数据项插入指定的位置,这三个参数是起始位置、要删除的数组项的个数以及要插入的项。此外,还可以指定要插入的更多的项。要插入的项的个数不必等于删除的项的个数。例如,arr.splice(2,1, "red","green")将删除数组arr中位置2处的项,然后在位置2处插入"red"和"green"。
栈和队列的概念
区别一
栈:后进先出(LIFO)结构,先添加的项先删除,栈中的插入和删除都只发生在栈顶部。
队列:先进先出(FIFO)结构,先添加的项最后删除,元素的插入操作只发生在队列的尾部,而删除操作则发生在队列的头部。
区别二
栈:顶部添加项叫“推入栈”,删除顶部项叫“弹出栈”。
队列:队尾添加项叫“put”或“入队”,队头删除项叫“get”或“出队”。
在Array类中的运用
栈:push()方法用于在Array结尾添加一个或多个项,pop()方法用于删除最后一个数组项(length-1),返回它作为函数值。
队列:push()方法把数据项加入队列(即在数组结尾添加数据项),shift()方法将删除数组中的第一个项,将其作为函数值返回。
Date类
Date类的方法(列在下表中)均用于设置或获取日期值的某部分。
方 法 |
说 明 |
toLocaleDateString() |
以地点特定的格式显示Date的时间部分 |
getTime() |
返回日期的毫秒表示 |
setTime(milliseconds) |
设置日期的毫秒表示 |
getFullYear() |
返回用四位数字表示的日期的年份(如2004而不只是04) |
getUTCFullYear() |
返回用四位数字表示的UTC日期的年份 |
setFullYear(year) |
设置日期的年份,参数必须是四位数字的年份值 |
setUTCFullYear(year) |
设置UTC日期的年份,参数必须是四位数字的年份值 |
getMonth() |
返回日期的月份值,由数字0(1月)到11(12月)表示 |
getUTCMonth() |
返回UTC日期的月份值,由数字0(1月)到11(12月)表示 |
setMonth(month) |
设置日期的月份为大于等于0的数字。对于大于11的数字,开始累计年数 |
setUTCMonth(month) |
设置UTC日期的月份为大于等于0的数字。对于大于11的数字,开始累计年数 |
getDate() |
返回该日期该月中的某天 |
getUTCDate() |
返回该UTC日期该月中的某天 |
setDate(date) |
设置该日期该月中的某天 |
setUTCDate(date) |
设置该UTC日期该月中的某天 |
getDay() |
返回该日期为星期几 |
getUTCDay() |
返回该UTC日期为星期几 |
setDay(day) |
设置该日期为星期几 |
setUTCDay(day) |
设置该UTC日期为星期几 |
getHours() |
返回日期中的小时值 |
getUTCHours() |
返回UTC日期中的小时值 |
setHours(hours) |
设置日期中的小时值 |
setUTCHours(hours) |
设置UTC日期中的小时值 |
getMinutes() |
返回日期中的分钟值 |
getUTCMinutes() |
返回UTC日期中的分钟值 |
setMinutes(minutes) |
设置日期中的分钟值 |
setUTCMinutes(minutes) |
设置UTC日期中的分钟值 |
getSeconds() |
返回日期中的秒值 |
getUTCSeconds () |
返回UTC日期中的秒值 |
setSeconds (seconds) |
设置日期中的秒值 |
setUTCSeconds (seconds) |
设置UTC日期中的秒值 |
getMilliseconds() |
Returns the millisecond value in the date. Note that this is not the millisecond value since January 1, 1970, but the millisecond value in the current time, such as 4:55:34.20, where 20 is the millisecond value of the time |
getUTCMilliseconds () |
Returns the millisecond value in UTC date |
setMilliseconds (milliseconds) |
Set the millisecond value in the date |
setUTCMilliseconds (milliseconds) |
Set millisecond value in UTC date |

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.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.