Objective:
1. Web-related development is becoming increasingly popular, and it is necessary to learn JS.
2. Learn one more language and want to learn more about the cultural connotation of one language.
3. Get to know the scripting language. I have been learning C, C ++ for a taste.
Learning path:
1. Project accumulation during previous internships
2. various pieces of information on the Internet
3. codecademy's online Js teaching courses (lengthy and meticulous courses, typing and hand cramps)
4. Various books, such as headfirst Js
Sporadic feelings: (I have been adding)
1. Attributes of classes in js can be identified by. Or ["xx "].
2. JS also has encapsulation. In the class constructor, var is used to define attributes or methods instead of this
3. The Function Definition of Js is not well divided, but the variable definition is followed by a semicolon.
4. this in functions and classes cannot be omitted.
5. Js instantiation is implemented through the new constructor.
Function Person (name, age ){
[Javascript]
This. name = name;
This. age = age;
}
// Let's make bob and susan again, using our constructor
Var bob = new Person ("Bob Smith", 30 );
This. name = name;
This. age = age;
}
// Let's make bob and susan again, using our constructor
Var bob = new Person ("Bob Smith", 30); 6. Use prototype to enable this attribute for each instance and implement inheritance
[Javascript]
// The original Animal class and sayName method
Function Animal (name, numLegs ){
This. name = name;
This. numLegs = numLegs;
}
Animal. prototype. sayName = function (){
Console. log ("Hi my name is" + this. name );
};
// Define a Penguin class
Function Penguin (name, numLegs ){
This. name = name;
This. numLegs = 2;
}
// Set its prototype to be a new instance of Animal
Penguin. prototype = new Animal ();
Var penguin = new Penguin ("Gigi ");
Penguin. sayName ();
// The original Animal class and sayName method
Function Animal (name, numLegs ){
This. name = name;
This. numLegs = numLegs;
}
Animal. prototype. sayName = function (){
Console. log ("Hi my name is" + this. name );
};
// Define a Penguin class
Function Penguin (name, numLegs ){
This. name = name;
This. numLegs = 2;
}
// Set its prototype to be a new instance of Animal
Penguin. prototype = new Animal ();
Var penguin = new Penguin ("Gigi ");
Penguin. sayName ();