JS Custom mixed Mixin Function Example _javascript tips

Source: Internet
Author: User
Tags mixed

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.