Js deep learning-differences between js prototype constructor attributes
In many js plug-ins, these two attributes are frequently used. I also used them when I write plug-ins myself. I know how to use them, but I don't know the specific differences. I have studied them today,
Constructor returns the constructor of an object (type instance). attributes and methods added through prototype are not returned.
Prototype returns a Type prototype that does not support post-dinner constructor.
Example:
<Script type = "text/javascript"> var cat = function (name, sex) {this. name = name; this. sex = sex; this. print = function () {console. log ("name:" + name + "\ r \ n sex:" + sex) ;}} cat. prototype. color = "red"; cat. prototype. printColor = function () {console. log ("color:" + this. color + "\ r \ n name" + this. name);} var myCat = new cat ("cavent", "boy"); </script>Js prototype attributes and constructor attributes
In the Google Chrome console, enter myCat. constructor, and the following is displayed:
function (name,sex){ this.name=name; this.sex=sex; this.print=function(){ console.log("name:"+name+" \r\n sex:"+sex); } }
Enter cat. prototype to display the following information:
Object {color: "red", printColor: function}color: "red"constructor: function (name,sex){printColor: function (){arguments: nullcaller: nulllength: 0name: ""prototype: Object__proto__: function Empty() {}
__proto__: Object
As follows: