current position:Home>JavaScript object
JavaScript object
2022-04-29 09:42:02【Lonely fighter】
1. Build an empty similar Person.java class
//1. Build an empty similar Person.java class
let Person = function () {
}
// Another way : function Person(){}
//2. Instantiate the class ( Create objects based on this class )
let p = new Person();
//3. You can dynamically add properties and methods to objects (java You are not allowed to )
p.name=" Zhang San ";// to p Object addition name attribute
p.age=18;
p.run=function () {
// to p Object addition run Method
alert(this.name+":"+this.age);
}
//4. Call the object's run Method
p.run();
2. Create a class with constructor
//1. Define an object with a constructor
let Car = function (name,price) {
this.name=name;
this.price=price;
this.cell = function () {
alert(" My name is "+this.name+" The price is :"+this.price+" element !");
}
}
// Another way of writing :
/** function Car(name,person){ this.name=" bentley "; this.price=500; this.cell=function(){ console.log(this.name+":"+this.price); } } */
//2. Instantiate objects ( Create objects based on this class )
let c1 = new Car(" Wei to Es8",580000);
c1.cell();// Call the object's cell Method
3. Instantiate an empty object directly ( Create objects directly )
let p1 = {
};
// Add properties and methods dynamically
p1.name=" Li Bai ";
p1.age=18;
p1.run = function () {
alert(this.name+":"+this.age);
}
p1.run();
4. Directly instantiate objects with properties and methods ( Directly create objects with properties and methods )
// Instantiate an object with properties and methods
let p2 = {
name:" Zhang San ",
age:66,
run:function () {
alert(this.name+":"+this.age);
}
}
p2.run();
copyright notice
author[Lonely fighter],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290746389040.html
The sidebar is recommended
guess what you like
Ajax learning notes
Relearn react (1) - recognize the life cycle
Small problems encountered by react usereducer and Solutions
CSS realizes the square of adaptive screen width
Nginx + ModSecurity setup
Bootstrap web job
bootstrap
Swoft 2. X Foundation (HTTP, database, redis)
Docker actual combat case 2: nginx load balancing
Vue basic syntax
Random recommended
- Go basic syntax 3 (socket, httpserver)
- Nginx configures HTTPS and calls http
- Nginx parsing vulnerability
- How can the backend package Vue projects quickly
- Netty configures WSS protocol access through nginx (Practical)
- Total permutation problem_ Not containing the same element and containing the same element_ Leetcode46_ Leetcode47_ Backtracking solution + java code
- How to upload and download files using Axios in nodejs
- Vue excel file upload
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url < https://conda.anaconda.org/fastai/noarch/repodat
- Multi function environmental monitoring pole scheme based on wireless gateway
- JPS in Hadoop, but http://hadoop01:50070/ How to solve the problem if there is no interface? 500ha70 cluster can't be accessed?
- Tool class for obtaining specific information in HTTP request
- UAV project tracking record 65 - wireless transceiver module circuit
- UAV project tracking record 76 - wireless transceiver module circuit
- Basic concept of angular velocity
- Front end login password encryption and decryption
- Vue parent-child component mutual transmission and intermodulation
- Vue nested loop array, select one of them and add the selected style
- The Vue seamless scroll list scrolls automatically
- Vue line graph moves dynamically to the right
- Install and configure nginx in Linux Environment
- Vue dynamically binds attributes and dynamically obtains attribute values
- Summary method of Vue value in key pair mapping
- Vue simply realizes the addition, deletion and modification of each tab page without route jump
- Vue time control common processing
- Vue validation array
- Simple and easy to let you know what AJAX is, even if you are a little white, a rookie can understand it!
- Receive the JSON string from the front end, and summarize the methods of parsing and value taking at the back end
- Solution: httpmessagenotreadableexception: JSON parse error: invalid UTF-8
- Vuetify: install vuetify from scratch
- Install CSS from tailwind
- Ubuntu 16 wireless network card model query and driver installation, Lenovo g400 bcm43142 network card WiFi
- Some color knowledge to understand at the front end
- Functional programming of front-end development
- A front-end interview question -- implementing an encapsulated Ajax device (promise version)
- Dynamic components of angular
- Front end written test pit -- JS implicit conversion
- Shallow understanding of HTTP
- React style modification background invalid
- Finding the k-th small element of ordered matrix (dichotomy idea)