1. Three functions of toString method1. Return a string representing an object 2. Type of detection object Object.prototype.toString.call(arr) == = "[object Array]" 3. Return the string corresponding to the number. console.log(10.toString(2)) //10 is specifically for binary '1010' js contains binary, octal, decimal and octal bases. 2. Return a string representing an object 1. toString is a method on the Object prototype. Every object has a Code: class Person{ constructor(name,age){ this.name=name this.age=age } } let zs=new Person('张三',18) console.log( zs.toString() ) // [object Object]
3. Custom toString() We can also define a method to override the default A custom The code is as follows: class Person{ constructor(name,age){ this.name=name this.age=age } // Override Object.prototype.toString() toString(){ return `Person{name=${this.name},age=${this.age}}` } } let zs=new Person('张三',18) console.log( zs.toString() ) //Person{name=张三,age=18} Many built-in objects in
This is the end of this article about the three functions of the You may also be interested in:
|
<<: Detailed explanation of the usage of the rare tags fieldset and legend
>>: Introduction to installing and configuring JDK under CentOS system
Previous words Line-height, font-size, and vertica...
HTML text formatting tags 標簽 描述 <b> 定義粗體文本 ...
This article shares the specific code of JavaScri...
Table of contents 1. classList attribute 2. Pract...
Anchor tag usage: Linking to a specific location i...
Table of contents Preface Global parameter persis...
<br /> This article is translated from allwe...
This article shares with you how to install the M...
Table of contents 1. Simple retrieval of data 2. ...
Declare the parameter name, type and permission y...
background We can use react-color to implement th...
You can use yum to install all dependencies toget...
MGR (MySQL Group Replication) is a new feature ad...
Problem Description As we all know, when writing ...
Wired network: Ethernet Wireless network: 4G, wif...