es6 class example
JavaScript
<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 Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}var Polygon = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
}'use strict'
class Polygon {
constructor(height, width) {
this.h = height;
this.w = width;
}
test() {
console.log("The height of the polygon: ", this.h)
console.log("The width of the polygon: ",this. w)
}
}
//creating an instance
var polyObj = new Polygon(10,20);
polyObj.test(); <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>
Also in JavaScript:
- Title
- find the last occurrence of a character in a string javascript
- Category
- JavaScript
- Title
- how to make one line if in js
- Category
- JavaScript
- Title
- constructor in js
- Category
- JavaScript
- Title
- change node version
- Category
- JavaScript
- Title
- how to change image source using javascript
- Category
- JavaScript
- Title
- axios post data vue js
- Category
- JavaScript
- Title
- append rotated triangle in anchor tag
- Category
- JavaScript
- Title
- abstraction in javascript
- Category
- JavaScript
- Title
- copy file javascript
- Category
- JavaScript
- Title
- command to create react app
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- fetch post js
- Category
- JavaScript
- Title
- format date js
- Category
- JavaScript
- Title
- cordova capacitor document viewer fail
- Category
- JavaScript
- Title
- how to remove 000webhost watermark 2019
- Category
- JavaScript
- Title
- how to access the second class of an element javascript
- Category
- JavaScript
- Title
- ibge api
- Category
- JavaScript
- Title
- functional component react
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- express img folder
- Category
- JavaScript
- Title
- Getting the differences between two objects javascript lib
- Category
- JavaScript
- Title
- ${ js
- Category
- JavaScript
- Title
- how to make a calculator websiteJS
- Category
- JavaScript
- Title
- debug node
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- gql TypeError: Object(...) is not a function
- Category
- JavaScript
- Title
- check if variable is undefined or null jquery
- Category
- JavaScript
- Title
- how to make a deep copy in javascript
- Category
- JavaScript
- Title
- go to another html page in javascript
- Category
- JavaScript
- Title
- is game development with javscript wrth it ?
- Category
- JavaScript
- Title
- add a slash to string in javascript
- Category
- JavaScript
- Title
- for(let [key,val] in obj){ messageBody = messageBody.replace("{"+ key + "}",val) }
- Category
- JavaScript
- Title
- how set defualt image for dropify
- Category
- JavaScript
- Title
- how to empty form after submit react
- Category
- JavaScript
- Title
- anguler test submit form
- Category
- JavaScript
- Title
- hashing in javascript
- Category
- JavaScript
- Title
- event import in angular
- Category
- JavaScript
- Title
- angular ngclass
- Category
- JavaScript
- Title
- ISS proxy express
- Category
- JavaScript
- Title
- get selected text js
- Category
- JavaScript
- Title
- How to write on a web page javascript
- Category
- JavaScript
- Title
- delete last element of array js
- Category
- JavaScript
- Title
- create element javascript with class
- Category
- JavaScript
- Title
- aws amplify get JWT TOKEN
- Category
- JavaScript
- Title
- how to set json type jquery ajax
- Category
- JavaScript
- Title
- finding an element ina na array in js
- Category
- JavaScript
- Title
- is javascript object oriented
- Category
- JavaScript
- Title
- get query parameters in node.js
- Category
- JavaScript
- Title
- express() vs express.router()
- Category
- JavaScript
- Title
- how to sort string aray in ts
- Category
- JavaScript
- Title
- how to make fizzbuzz in javascript
- Category
- JavaScript
- Title
- hover vanilla javascript
- Category
- JavaScript
- Title
- how to avoid inheritance in angular
- Category
- JavaScript
- Title
- javascript check if variable exists
- Category
- JavaScript
- Title
- integers to space separated string in javascript
- Category
- JavaScript
- Title
- how to check how many strings are in a sentence javascript
- Category
- JavaScript
- Title
- inline style boarder radius jsx
- Category
- JavaScript
- Title
- convert date to string javascript
- Category
- JavaScript
- Title
- how to return the number of nodes in a linked list
- Category
- JavaScript
- Title
- how to paste in input field react native
- Category
- JavaScript
- Title
- javascript array exists check
- Category
- JavaScript
- Title
- convert this to d3.select()
- Category
- JavaScript
- Title
- crear componente con angular cli
- Category
- JavaScript
- Title
- duplicate encoder
- Category
- JavaScript
- Title
- group by in javascript
- Category
- JavaScript
- Title
- javascript check if element is visible on screen
- Category
- JavaScript
- Title
- int to string javascript
- Category
- JavaScript
- Title
- how to program an array in js
- Category
- JavaScript
- Title
- javascript check if elements of one array are in another
- Category
- JavaScript
- Title
- convert 24 hour to 12 hour moment js
- Category
- JavaScript
- Title
- javascript array flatten
- Category
- JavaScript
- Title
- hide element by name javascript
- Category
- JavaScript
- Title
- check if string is datestring javascript
- Category
- JavaScript
- Title
- array remove first element javascript
- Category
- JavaScript
- Title
- how to auto refresh page in javascript
- Category
- JavaScript
- Title
- if (req.url === "/script.js")
- Category
- JavaScript
- Title
- express js continous GET /json/version
- Category
- JavaScript
- Title
- How do I get Month and Date of JavaScript in 2 digit format
- Category
- JavaScript
- Title
- createnodefield
- Category
- JavaScript
- Title
- fetch api javascript
- Category
- JavaScript
- Title
- can you do a join() in js without the commas
- Category
- JavaScript
- Title
- event listener in react
- Category
- JavaScript
- Title
- how to convert whole strig in lowercase in js
- Category
- JavaScript
- Title
- how to code print in javascript
- Category
- JavaScript
- Title
- how to format unix timestamp javascript
- Category
- JavaScript
- Title
- javascript capitalize first letter
- Category
- JavaScript
- Title
- change title react
- Category
- JavaScript
- Title
- check value exist in array javascript
- Category
- JavaScript
- Title
- function redirect javascript
- Category
- JavaScript
- Title
- javascript check if value in array
- Category
- JavaScript
- Title
- how to push values in array
- Category
- JavaScript
- Title
- how to set random dice image with js
- Category
- JavaScript
- Title
- javascript check if string is json parsable
- Category
- JavaScript
- Title
- fetch api based on id nodejs and mongodb
- Category
- JavaScript
- Title
- javascript change element id
- Category
- JavaScript
- Title
- how to pass a variable to jspf
- Category
- JavaScript
- Title
- html table to excel javascript
- Category
- JavaScript
- Title
- how to convert array to uppercase in javascript
- Category
- JavaScript
- Title
- how to add data-toggle and data-target using jquery
- Category
- JavaScript