0
[javascript] Syntax for adding method to retrieve properties from that class?
Please help with example.
4 Respuestas
+ 2
Properties of HTML class attribute or OOP class?
+ 2
Answer about constructor function already here,so Ill add class one...
class User {
constructor (name){
this.name = name
}
logName() {
console.log(this.name)
}
}
let Alex = new User(Alex)
Alex.logName()
//Alex
+ 1
// Possibly you are asking about method constructor
function Name( age ){
this.age = age;
// A class method
this.dob = function(){
return 2017 - this.age;
}
}
var person = new Name;
// dob for Date of Birth
alert(person.dob(17));
// Alerts 2000;
+ 1
properties of OOP class