How does javascript extend built-in objects
This article mainly introduces javascript how to expand the built-in object related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this javascript article on how to expand built-in objects, let's take a look.
Description
1. Through the prototype object, you can extend the customization method of the original built-in object. For example, the ability to add a custom courtship number to an array.
2. Array and string built-in objects cannot override the prototype object operation Arrray.prototype= {}, only in the way of Arrray.prototype.xxx=function () {}.
Example
/ / the application of the prototype object extends the built-in object method Array.prototype.sum = function () {var sum = 0; for (var I = 0; I < this.length; iTunes +) {sum + = this [I];} return sum;} / / Array.prototype = {/ / sum: function () {/ / var sum = 0; / / for (var I = 0; I < this.length; iTunes +) {/ / sum + = this [I]; / /} / / return sum / /} / /} var arr = [1,2,3]; console.log (arr.sum ()); console.log (Array.prototype); var arr1 = new Array (11,22,33); console.log (arr1.sum ()); this is the end of the article on "how javascript extends built-in objects". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to expand built-in objects in javascript". If you want to learn more, you are welcome to follow the industry information channel.