I was reading thread thread216-1282657 and think I had that flash of light moment and would appreciate your input!
in the thread it shows this as a simple example
now does this mean 'obj' function is a class - defining the components / vars / methods which make up the object of class 'obj'
then myObj = new obj(); creates a new object of class 'obj'.
which has a method 'mymethod' and a property 'myproperty' which is of value '1'.
So if I want to perform the Method on the object 'myObj' of class 'obj' I use...
If I want change a property value i use
To expand on this to create other properties and methods i would do
I have a form with two input fields and a button with an onclick which calls showSum.
Have I grasped this OO thing finaly?
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
in the thread it shows this as a simple example
Code:
function obj(){
this.myproperty = 1;
this.mymethod = function(){
alert("Hi");
}
}
var myObj = new obj();[code]
then myObj = new obj(); creates a new object of class 'obj'.
which has a method 'mymethod' and a property 'myproperty' which is of value '1'.
So if I want to perform the Method on the object 'myObj' of class 'obj' I use...
Code:
myObj.mymethod();
Code:
myObj.myproperty = 20;
To expand on this to create other properties and methods i would do
Code:
function mySum(){
this.mynum1 = 0;
this.mynum2 = 0;
this.total = 0;
this.sumit = function(){
this.total = this.mynum1 + this.mynum2;
alert("Sum Total : " + this.total;
}
}
var mySumObj = new mySum();
function showSum(){
var frm = document.getElementById('myformid');
if(parseInt(frm.myfield1.value) > 0 && parseInt(frm.myfield2.value > 0){
mySumObj.mynum1 = frm.myfield1.value;
mySumObj.mynum2 = frm.myfield2.value;
mySumObj.sumit();
}
else{alert("Input invalid");}
}
I have a form with two input fields and a button with an onclick which calls showSum.
Have I grasped this OO thing finaly?
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.