Home >Web Front-end >JS Tutorial >JavaScript learning summary
Purpose of learning:
1. Web-related development is becoming more and more popular, and it is very necessary to learn JS
2. Learn one more language and want to know more about the cultural connotation of a language
3. Get to know the scripting language, which I have been using before Learn C, C++ for a change
Learning methods:
1. Project accumulation during previous internships
2. Various fragmentary information on the Internet
3. Codecademy’s online Js teaching course (long and detailed Course, my hands cramped while typing)
4. Various books, such as "headfirst Js", etc.
Sporadic feelings:
1. The attributes of classes in .js can be used. You can also use ["xx" ] to identify
2. JS also has encapsulation. In the constructor of the class, use var to define properties or methods instead of this
3. JS’s function definition is not separated well, but there is a semicolon after the variable definition.
4. This cannot be omitted in functions and classes
5. The instantiation of Js is achieved 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 so that each instance has this attribute, and also implements 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();