JS is how to implement inheritance using apply:
JavaScript is an object-oriented language, of course, inheritance is one of its important characteristics, such as the general can use the prototype implementation of inheritance, but the use of apply but can implement inheritance, the following through the code example introduced here, about the Apply function is not introduced here, specifically, you can see The role and difference of the JavaScript call () and apply () section. Here's a look at the code example:
functionParent (username) { This. username=username; This. sayhello=function() {alert ( This. username); } } functionChild (Username,password) {parent.apply ( This,NewArray (username)); This. password=password; This. sayworld=function() {alert ( This. Password); } } varParent=NewParent ("Ant Tribe")); varChild=NewChild ("Antzone", "8888"); Parent.sayhello (); Child.sayhello (); Child.sayworld ();
The above code to achieve a simple inheritance effect, the code is relatively simple here is not much introduction, if there are any questions can be thread message.
For a pointer to this, you can refer to the This usage section of JavaScript .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=11309
For more information, refer to: http://www.softwhy.com/javascript/
JS How to use apply to implement the inheritance