- 1
Please associate the "testData" constructor function below with a method called "mymethod":
function testData (first, second) { this.first = first; this.second = second; this.checkData = ; }
8 Antworten
+ 3
function testData (first, second) {
this.first = first;
this.second = second;
this.checkData = mymethod;
}
+ 2
mymethod
+ 1
please see the code below
// declare a constructor
function student(id, name, dept){
this.name = name;
this.id =id;
this.dept = dept;
//adding method
this.changeName = function change(name){
this.name = name;
}
}
//create an object
var student1 = new student("1","Arif","SE");
console.log(student1.name)
//output "Arif"
//change the name & contain in a variable
var accessMethod = student1.changeName("Rahim");
console.log(student1.name);
//"Rahim"
i guess that you want to add function name myMethod , but it doesnt matter now. you have to access through your properties cause you assign the function in that properties. you cant access through that function name. There is another way to do it. at now its ok.
+ 1
this.checkData = mymethod;
+ 1
Methods
=============
Please associate the "testData" constructor function below with a method called "mymethod":
function testData (first, second) {
this.first = first;
this.second = second;
this.checkData =
mymethod
;
}
0
Hi Chandra
Not sure if this is what you want
function testData (first, second) {
this.first = first;
this.second = second;
this.myMethod = function (params){ code for myMthod}
;
}
You can also declare externally
myOtherMethod(params) {
// ...do something else
}
};
You will find this in the course
0
mymethod
0
mymethod