This example describes the JS custom mixed mixin function. Share to everyone for your reference, specific as follows:
<script type= "Text/javascript" >/* Add function * * functions augment (Receivingclass, Givingclass) {for (MethodName in Givin Gclass.prototype) {if (!receivingclass.prototype[methodname]) {Receivingclass.prototype[methodname] = GIVINGCLASS.P
Rototype[methodname];
}}///function augment (Receivingclass, Givingclass) {if (arguments[2]) {//only give certain. for (var i = 2, Len = Arguments.length i < len; i++) {receivingclass.prototype[arguments[i]] = Givingclass.prototyp
E[arguments[i]];
} else {//Give all methods. For (methodname in Givingclass.prototype) {if (!receivingclass.prototype[methodname]) {Receivingclass.prototype[met
Hodname] = Givingclass.prototype[methodname];
var Author = function Author (name, books) {//constructor this.name = name; This.books = Books | |
' Default value ';
};
Author.prototype = {Getname:function () {return this.name;
}, Getbooks:function () {return this.books;
}
}; var Editor = Function Editor () {};
Editor.prototype = {Hello:function () {return ' Hello, ' +this.name;
}
};
Augment (Author, Editor);
var author = new author (' Ross harmes ', [' JavaScript design Patterns ']);
Console.log (Author.getname ());
Console.log (Author.getbooks ());
Console.log (Author.hello ());
</script>
Results:
After stitching, author gets the Hello method, the property or its own name.
For more on JavaScript related content to view the site topics: "JavaScript common function Tips Summary", "JavaScript object-oriented tutorial", "JavaScript in the JSON Operation tips Summary", " JavaScript switching effects and techniques summary, "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and Skills summary", "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", JavaScript traversal algorithm and techniques summary and JavaScript mathematical Operational Usage Summary
I hope this article will help you with JavaScript programming.