1. The importance of prototype mode is not only in the creation of custom types, but even all native reference types (obejct, Array, String, and so on) define methods and properties on the constructor's prototype. The following code can prove:
Alert (typeof// output: function alert (typeof// output: function
Through the prototype of the native object, you can not only get references to all the default methods, but also define new methods. You can modify the prototype of a native object just as you would modify the prototype of your own definition object, so you can add the method we need at any time to the native object. The code is as follows:
string.prototype.startswith=function(TXT) { returnthis. indexOf (TXT) ==0 ; } var msg= "Hello world!" ; Alert (Msg.startswith (// output: True, stating that MSG starts with a "Hello" word
JavaScript Object-oriented learning five (JS native reference type Array, object, string, etc.) Introduction to prototype objects