javascript classes
JavaScript
class ClassMates{
constructor(name,age){
this.name=name;
this.age=age;
}
displayInfo(){
return this.name + "is " + this.age + " years old!";
}
}
let classmate = new ClassMates("Mike Will",15);
classmate.displayInfo(); // result: Mike Will is 15 years old!class Car {
constructor(brand) {
this.carname = brand;
}
present() {
return "I have a " + this.carname;
}
}
mycar = new Car("Ford");
document.getElementById("demo").innerHTML
= mycar.present();
<script>
class Student {
constructor(rno,fname,lname){
this.rno = rno
this.fname = fname
this.lname = lname
console.log('inside constructor')
}
get fullName(){
console.log('inside getter')
return this.fname + " - "+this.lname
}
}
let s1 = new Student(101,'Sachin','Tendulkar')
console.log(s1)
//getter is called
console.log(s1.fullName)
</script>class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
// Getter
get area() {
return this.calcArea();
}
// Method
calcArea() {
return this.height * this.width;
}
}
const square = new Rectangle(10, 10);
console.log(square.area); // 100<script>
class Student {
constructor(rno,fname,lname){
this.rno = rno
this.fname = fname
this.lname = lname
console.log('inside constructor')
}
set rollno(newRollno){
console.log("inside setter")
this.rno = newRollno
}
}
let s1 = new Student(101,'Sachin','Tendulkar')
console.log(s1)
//setter is called
s1.rollno = 201
console.log(s1)
</script>let Person = class {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
Also in JavaScript:
- Title
- javacript getHTTPURL
- Category
- JavaScript
- Title
- express get query params from url
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- adding bootstrap to angular
- Category
- JavaScript
- Title
- bootstrap 4 open tab when opening modal
- Category
- JavaScript
- Title
- ExoPlayer with auto linking react native
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- change select value jquery
- Category
- JavaScript
- Title
- get screen width javascript
- Category
- JavaScript
- Title
- ajax request qml
- Category
- JavaScript
- Title
- forever loop in js
- Category
- JavaScript
- Title
- body-parser node
- Category
- JavaScript
- Title
- get unique id angular
- Category
- JavaScript
- Title
- fatorial recursivo em javascript
- Category
- JavaScript
- Title
- How to create a function in javascript
- Category
- JavaScript
- Title
- custom processing datatables
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- how to include local image files in javascript object
- Category
- JavaScript
- Title
- client side redirect javascript
- Category
- JavaScript
- Title
- how to get the index of an array in javascript
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- global site tag (gtag.js) - google analytics gatsby
- Category
- JavaScript
- Title
- basic javascript
- Category
- JavaScript
- Title
- javascript add item to list
- Category
- JavaScript
- Title
- convert array object to string javascript
- Category
- JavaScript
- Title
- copy file javascript
- Category
- JavaScript
- Title
- disable autocomplete in react fields
- Category
- JavaScript
- Title
- firebase cheat sheet
- Category
- JavaScript
- Title
- how to send an alert in javascript
- Category
- JavaScript
- Title
- get current screen name react navigation
- Category
- JavaScript
- Title
- atom javascript es6 linter
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- create object javascript
- Category
- JavaScript
- Title
- document queryselectorall and map javacript
- Category
- JavaScript
- Title
- how to check if 2 sprites are touching js
- Category
- JavaScript
- Title
- adding cors in angular
- Category
- JavaScript
- Title
- array shift javascript
- Category
- JavaScript
- Title
- int cating javascript
- Category
- JavaScript
- Title
- add and remove class in jquery
- Category
- JavaScript
- Title
- how to get data in json format in javascript
- Category
- JavaScript
- Title
- angular local storage
- Category
- JavaScript
- Title
- javascript are arrays equal
- Category
- JavaScript
- Title
- axios file upload
- Category
- JavaScript
- Title
- how to add onclick event in javascript
- Category
- JavaScript
- Title
- getting the value of pi in javascript
- Category
- JavaScript
- Title
- javascript adding an array to an array
- Category
- JavaScript
- Title
- how to get the next item in map() js
- Category
- JavaScript
- Title
- fetch multiple urls javascript
- Category
- JavaScript
- Title
- chrome extension get current tab from popup
- Category
- JavaScript
- Title
- check if string is datestring javascript
- Category
- JavaScript
- Title
- drupal 8 node has field
- Category
- JavaScript
- Title
- float to currency
- Category
- JavaScript
- Title
- console log all array values node
- Category
- JavaScript
- Title
- how to access child img src in jquery
- Category
- JavaScript
- Title
- adding delay in javascript foreach loop
- Category
- JavaScript
- Title
- angular attach component to body
- Category
- JavaScript
- Title
- foreach over array javascript
- Category
- JavaScript
- Title
- .shift js
- Category
- JavaScript
- Title
- generate thumbnail of pdf using pf js
- Category
- JavaScript
- Title
- express validator always return error
- Category
- JavaScript
- Title
- how to check version of node js in cmd
- Category
- JavaScript
- Title
- http requests in vue 3
- Category
- JavaScript
- Title
- how to redirect react router from the app components
- Category
- JavaScript
- Title
- how to add text to h2 with jquery
- Category
- JavaScript
- Title
- add dev dependency yarn
- Category
- JavaScript
- Title
- duplicate encoder
- Category
- JavaScript
- Title
- geojson longitude latitude order
- Category
- JavaScript
- Title
- deprecationwarning: mongoose
- Category
- JavaScript
- Title
- angular event scroll end of page
- Category
- JavaScript
- Title
- find least common multiple javascript
- Category
- JavaScript
- Title
- how to run function after animation complete jquery
- Category
- JavaScript
- Title
- anagram javascript example
- Category
- JavaScript
- Title
- Error: Can't resolve 'fs' webpack
- Category
- JavaScript
- Title
- hot to start cypress
- Category
- JavaScript
- Title
- document get element by tag
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- how to create uuid in javascript
- Category
- JavaScript
- Title
- how to set text for label in jquery
- Category
- JavaScript
- Title
- how to add javascript to html
- Category
- JavaScript
- Title
- how to instialise var in js
- Category
- JavaScript
- Title
- delete previous line node
- Category
- JavaScript
- Title
- export default react
- Category
- JavaScript
- Title
- error sending empty object express
- Category
- JavaScript
- Title
- for Loop continue
- Category
- JavaScript
- Title
- find intersection between two object arrays javascript
- Category
- JavaScript
- Title
- bot discord comment récupérer la pdp de quelqu'un
- Category
- JavaScript
- Title
- http request javascript
- Category
- JavaScript
- Title
- install vue js
- Category
- JavaScript
- Title
- How can I upload files asynchronously
- Category
- JavaScript
- Title
- find a single element in array of objects javascript
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- convert json to arraylist java
- Category
- JavaScript
- Title
- functional component react
- Category
- JavaScript
- Title
- dynamic forms in react
- Category
- JavaScript
- Title
- append to array js
- Category
- JavaScript
- Title
- grapejs html editor
- Category
- JavaScript
- Title
- how to access array datat in class component react
- Category
- JavaScript
- Title
- compare two array javascript
- Category
- JavaScript
- Title
- how to add data-toggle and data-target using jquery
- Category
- JavaScript
- Title
- Attempted import error: 'uuid' does not contain a default export (imported as 'uuid').
- Category
- JavaScript