


Detailed explanation of built-in objects in js object-oriented (code)
本篇文章给大家带来的内容是关于js面向对象中内置对象的详解(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
方法
String
获取字符串长度Length属性
连接字符串:concat(String, String)
获取索引值:indexOf(String)
根据索引值获取单个字符:charAt(Index)
从起始索引fromIndex开始截取长度length的字符串:substr(fromIndex,length)
截取 起始索引startIndex 到 结束索引endIndex的子字符串,结果包含startIndex处的字符,不包含endIndex处的字符:substring(startIndex,endIndex)/slice(startIndex,endIndex)
按给定字符串分割,返回分割后的多个字符串组成的字符串数组:split(String)
使用选择的分隔符将一个数组合并为一个字符串:join(String)
大小写转换:toLowerCase()/toUpperCase()
replace
判断是否包含指定字符串:contains(String)
判断是否为空:isEmpty()
html编码和解码:escapeHTML() unescapeHTML()
replace的用法:
//$符的使用 myString=myString.replace(/(Marvin)/g,"<font color=red>$1</font>"); //函数 function test(str){ return "<font color='red'>"+str+"</font>"} myString=myString.replace(/(Marvin)/g,test);
Array
添加和删除:shift unshift【从数组开头开始添加或者删除】,pop push【从数组末尾添加或者删除】
数组合并,参数添加到原数组中,返回新的数组:concat()
排序: sort() 从小到大 reverse() 从大到小
数组截取: slice(start,end)
数组拼接成字符串:join(separator)
splice()
Date
date = new Date(2015, 2, 27, 12, 59, 59);
- date.toLocaleString(): 2015年3月27日 12:59:59
- date.toLocaleString(): 2015年3月27日 12:59:00
- date.toLocaleString(): 2015年3月27日 12:00:00
- date.toLocaleString(): 2015年3月27日 12:00:00
- date.toLocaleString(): 2015年3月27日 12:00:00
date = new Date(“month dd,yyyy hh:mm:ss”):date = new Date(‘2014-12-25’)
getFullYear()
getYear()
getMonth()
getDate(): 获取几号 - 0 - 31 比如25
getDay(): 获取星期几 - 比如星期3的3
getHours()
getMinutes()
getSeconds()
getMilliseconds()
getTime(): 获取相对于1970-01-01的毫秒值
Function
Arguments
Length
Caller属性 获取调用当前函数的函数。caller属性只有当函数正在执行时才被定义
Callee属性 返回正被执行的 Function 对象,即指定的 Function 对象的正文
constructor 属性 就是用来构造对象实例的函数引用。
Prototype属性获取对象的原型。每一个构造函数都有一个prototype属性,指向另一个对象。这个对象的所有属性和方法,都会被构造函数的实例继承。这意味着,我们可以把那些不变的属性和方法,直接定义在prototype对象上。
Apply方法 调用函数,并用指定对象替换函数的this值,同时用指定数组替换函数的参数。
Call方法 调用一个对象的方法,用另一个对象替换当前对象。
Bind方法 对于给定函数,创建具有与原始函数相同的主体的绑定函数。
toString 返回对象的字符串表示形式。
call::借用,伪数组
//call的用法:借用() var myclass={getAllPersonNumbers:function(age){return age}}; var student={ getDetail:function(){ return {name:'Marvin',age:20} } }; myclass.getAllPersonNumbers.call(student) //call的用法:借用(传参) var myclass={getAllPersonNumbers:function(){return 33}}; var student={ getDetail:function(){ return {name:'Marvin',age:20} } }; myclass.getAllPersonNumbers.call(student,20) //call 的用法伪数组(将伪数组改为真 的数组) var json = {1:'',2:'',length:2}
call方法会修改this的指针,在call后改变被借用的函数的this指针指向自身。
//call将指向全局的this的指针指向了自身student myclass.getAllPersonNumbers.call(student,20)
伪数组:获取到的dom就是一个伪数组,jquery获取到的也是一个伪数组
var ss = {0: 'Marvin', 1: 'lili'}Array.prototype.slice.call(ss)/ /能将具有length属性的对象转成数组 => [Marvin , lili]
apply::
//循环式获取最大值 function getMax(arr){ var arrLen=arr.length; for(var i=0,ret=arr[0];i<arrLen;i++){ ret=Math.max(ret,arr[i]); }return ret; } //max()只能传递离散的数值 //获取数组中的最大值 myclass.getAllStudentsNumbers.apply(student,[10,200])return Math.max.call(null,1,2,3,4,5) === return Math.max.apply(null,arr); //合并数组 Array.prototype.push.apply(arr1,arr2)
相关推荐:
Detailed explanation of JS’s built-in object String
The above is the detailed content of Detailed explanation of built-in objects in js object-oriented (code). For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

There are ten types of Python built-in objects: "int", "float", "str", "list", "tuple", "dict", "set", "bool", "NoneType" and "function": 1. int , used to represent integer values; 2. float, used to represent real values; 3. str, used to represent text data; 4. list, used to store a series of ordered elements; 5. tuple, tuple type; 6 , dict, a data structure used to store key-value pairs, etc.

ASP built-in objects include Request, Response, Session, Application, Server, Session.Contents, Application.Contents, Server.CreateObject, Server.MapPath, Server.Execute, Server.Transfer, etc. Detailed introduction: 1. Request: represents HTTP request object, etc.

Master PHP built-in objects: Learn the operation and usage of commonly used built-in objects. Specific code examples are required. As a widely used back-end development language, PHP provides many powerful built-in objects that can help us develop and manage websites efficiently. Mastering the operation and usage of these built-in objects is crucial for PHP developers. This article will introduce some commonly used PHP built-in objects and provide specific code examples. 1. String processing object (String) String processing is often used in Web development, PHP

Nodejs built-in objects include Global, Process, Buffer, Console, Timer, EventEmitter, Stream, File System, HTTP, URL, Query String, Crypto, Path, OS, etc. Detailed introduction: 1. Global: global object, similar to the window object in the browser environment, which can be accessed anywhere; 2. Process, etc.

Vue's built-in objects include Vue, Vue instance, data, el, options, parent, root, children, slots, scopedSlots, refs, isServer, attrs and listeners. Vue.js is a progressive JavaScript framework for building user interfaces. In Vue.js, there are some built-in objects or global APIs that can be used to create and manage Vue applications.

dom内置对象有:1、document;2、window;3、navigator;4、location;5、history;6、screen;7、document.documentElement;8、document.body;9、document.head;10、document.title;11、document.cookie。

Built-in objects usually refer to objects with specific functions and properties provided by the programming language itself. These objects are usually part of the programming language and can be used directly in the code without additional import or loading. By using built-in objects, development Users can easily perform various operations, and these objects have the same behavior in different programs.

JSP built-in objects refer to some predefined objects in JSP. Can be used directly in the page, these built-in objects provide many useful functions and properties, making it easier for developers to process and manipulate data. Common built-in objects in JSP include request object, response object, out object, session object, application object, config object, pageContext object, exception object, etc.
