This article mainly introduces the basic learning tutorial on prototype inheritance in JavaScript. prototype-based inheritance is the basic method for implementing the inheritance features in Object-Oriented JavaScript, for more information, see classes and objects in most programming languages. One class can inherit other classes.
In JavaScript, inheritance is prototype-based, which means that there is no class in JavaScript. Instead, one object inherits from another object. :)
1. Inheritance,
Original link: http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html5 ways to summarize inheritance between objects:For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor for the "Cat" object.
function Cat (name,color) {
://www.cnblogs.com/glacierh ):
code highlighting produced by actipro codehighlighter (freeware) http://www.CodeHighlighter.com/ --> Public class animal { Public virtual void eat () { " animal eat... " ); } Public class CAT: animal { Public override void eat () { " cat eat... " ); } Public class dog:
The first part of the series focuses on how to "encapsulate" data and methods, and how to generate instances from prototype objects.Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor fo
Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor for the "Cat" object.
function Cat (name,color) {
THIS.name = name;
This.color = color;
}
How to make "cat"
Probably Java arrays are familiar to me, and I recently encountered a problem with the memory allocation of Java arrays.Oh. All of a sudden, I found a lot of books. The phrase "basic data types are stored in stack memory and objects are saved in heap memory" is completely wrong. Here's a simple example code:
Copy Code code as follows:
public class Test {
public static void Main (string[] argv) {
Statically initializing an array
String[] names = {"Michael", "Orson", "Andrew"}
NanyiDate: May 23, 2010The first part of the series focuses on how to "encapsulate" data and methods, and how to generate instances from prototype objects.Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There i
Http://blog.csdn.net/lovecady/article/details/2562026
When an assembly reference is added, a type conflict may occur. That is, if the type defined by your application in another assembly has the same name, you must add an alias for the reference.
When you add an alias to an assembly, the namespace used in the assembly will be resolved under the alias instead of global.
To add an alias to an assembly, first add an Assembly reference in Visual Studio 2005, and then open the reference folder in so
. [Reliabilitycontract (consistency. willnotcorruptstate, Cer. success)] [targetedpatchingoptout ("performance critical to inline upload SS ngen image boundaries")] public static bool referenceequals (Object obja, object objb); // Abstract: // return indicates the current system. object System. string. //// Return result: // system. String, indicating the current system. object. Public Virtual string tostring ();}
From the code above, we can see that there are several basic methods of all types
behaves much like call and Check_output. If you're using version 3.5 or later, take a look at run's documentation, which has some useful examples. Otherwise, if you're using a previous version of Python 3.5 or if you want to keep backwards compatibility, the call and check_output snippets above are your safest and simplest choice.Beautiful printingDevelopment uses the Pprint module instead of the standard print function, which allows the shell to output more readable information. This makes it
method overrides can actually be considered as the upgrade of the parent class method (or function upgrade) ...First look at the difference between this and the Super keywordpublic class test{public static void Main (string[] args) {Cat c=new Cat (); System calls no parameter construct create object CC.eat ();}}Class animal{public void Eat () {System.out.println ("Animal Eats");}}Class Cat extends
Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor for the "Cat" object.
function Cat (name,color) {
THIS.name = name;
This.color = color;
}
How to make "cat"
Today's introduction is about five ways to "inherit" between objects.For example, there is now a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor for the "Cat" object.
function Cat (name,color) {
THIS.name = name;
This.color = color;
}
How to make "cat"
Polymorphic :Object-oriented third feature, definition: a certain kind of things exist in many forms, for example, the function has polymorphism, a function of the same name, its parameter list is not the same, its existence is not the same, there is the same function, placed in the parent class and placed in the subclass, its existence is not the same.The object also has polymorphism.Example: Animals have pigs, cats, dogs, etc.Cats This object corresponds to the class is the Cat classCat x =
Supertype (name) {THIS.name = name;This.clone = ["Red", "Blue", "green"];}SuperType.prototype.sayName = function () {alert (this.name);}Function subtype (name,age) {Supertype.call (This,name);This.age = age;}Sybtype.prototype = new Supertype ();SubType.prototype.constructor = subtype;SubType.prototype.sayAge = function () {alert (this.age);}The so-called parasitic combinatorial inheritance is to inherit the attribute by borrowing the constructor, and inheriting the method through the hybrid for
responsibilities. But when the program has been written, it's too time-consuming. So, simply modifying the class T and using it to take charge of two responsibilities is a good choice, although this is contrary to the principle of single responsibility. (The risk is the uncertainty of the spread of responsibility, because we would not think of this duty p, which could spread to P1,P2,P3,P4 in the future ...) Pn. So remember to refactor the code immediately before it spreads to the point where w
Now there is a constructor for an "animal" object.
function Animal () {
This.species = "Animal";
}
There is also a constructor for the "Cat" object.
function Cat (name,color) {
THIS.name = name;
This.color = color;
}
first, constructor bindingThe first method is also the simplest method, using the call or Apply
the above story in JavaScript code as follows:var makeSound = function( animal ){ if ( animal instanceof Duck ){ console.log( ‘嘎嘎嘎‘ ); }else if ( animal instanceof Chicken ){ console.log( ‘咯咯咯‘ ); }};var Duck = function(){};var Chicken = function(){};makeSound( new Duck() ); //嘎嘎嘎makeSound( new Chicken() ); This code does reflect
the above story in JavaScript code as follows:var makeSound = function( animal ){ if ( animal instanceof Duck ){ console.log( ‘嘎嘎嘎‘ ); }else if ( animal instanceof Chicken ){ console.log( ‘咯咯咯‘ ); }};var Duck = function(){};var Chicken = function(){};makeSound( new Duck() ); //嘎嘎嘎makeSound( new Chicken() ); This code does reflect
Directory
I. Reasons for not needing to instantiate
I. Types that cannot be instantiated
Second, abstract class
Third, the interface
3.1. Why interfaces are required
3.2, the characteristics of the interface
Iv. Final (final)
4.1. Final Modified Class
4.2. Final Modification method
4.3. Final modified variable
V. Video and sample download
Vi. Interview Questions
I. Reasons for not needing to instantiateLook at an
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.