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
This article uses an example to describe how to v...
Table of contents Causes of MySQL Table Fragmenta...
Table of contents Preface 1. Download a single fi...
Table of contents Find and fix table conflicts Up...
[Looking at all the migration files on the Intern...
What are slots? The slot directive is v-slot, whi...
Table of contents Overview Subqueries Subquery Cl...
This article describes how to use MySQL to export...
This article uses examples to describe the basic ...
<br />Original article: http://www.alistapar...
Table of contents 1. Array.at() 2. Array.copyWith...
Table of contents Overview File Descriptors Synch...
Table of contents 1. Lvs Introduction 2. Lvs load...
There are many servers that can host static websi...
need Configuring DingTalk alarms in Zabbix is s...