Encapsulates all information within a constructor, by initializing the prototype in the constructor, preserving the advantages of using both constructors and prototypes, and determining whether the prototype needs to be initialized by checking whether a method that should be stored is valid. (if judged)
function Person (name,age,job) { this.name=name; This.age-age; This.job=job; Determine if the method exists if (typeof this.sayname!= "function") { person.prototype.sayname=function () { alert ( this.name);} ; } var friend=new person ("Nicholas", "Engineer"); Friend.sayname ();
Note: When using the dynamic prototype pattern, you cannot rewrite the prototype with object literals, which will cut off the connection between the instance and the new prototype, using the ISSTANCEOF operator to determine the type of object being created.
Function Creation Object (4) dynamic prototype mode