+ 1
What's the problem with this JS code?
Contact Manager function contact(name, number) { this.name = name; this.number = number; this.print =()=>{ console.log(this.name+":"+this.number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print();
8 Respostas
+ 5
In arrow function this keyword is inherited from the parent. I mean arrow function does not have its own this key word. Instead, you should use function expressions not the arrow functions. That is the reason!
I hope I'm understood!đ
+ 4
Hi dear Lawis.
Try this piece of code.
And let me know the resultđđčđčđ
function contact(name, number) {
this.name = name;
this.number = number;
this.print =function(){
var x =this.name
var y =this.number
console.log(x+": "+y)
}
}
var a = new contact("David", 12345);
var b = new contact("Amy", 987654321)
a.print();
b.print();
+ 1
JavaScript code
+ 1
It runs fine in the code playground.
0
Jonalyn Limentang
Please specify which language in the tags of your post
0
Jonalyn Limentang
there is a space missing from your print() func.
The bit after the colon :
console.log(this.name+": "+this.number);
0
It's ok!
Can you please insert the code here?
- 2
Can you try that
this.print = bornYear
function bornYear () {
console.log(this.name + ':'+ this.number ); }