Javascript OOP Object
by Prasad
HTML
<form id="ourForm">
<label>First Name</label><input type="text" /><br />
<label>Last Name</label><input type="text" /><br />
<label>Email</label><input type="text" /><br />
<input type="submit" value="submit" />
</form>
JavaScript
// JavaScript Document
//************************************************************************************************************
//Using Constructor Function
//************************************************************************************************************
function Classname (){
this.iam= "object";
this.whatami= function(){
console.log("I am "+this.iam+ "// this initialized from Constructor");
};
}
var classObject= new Classname();
classObject.whatami();
//************************************************************************************************************
//Using Literal
//************************************************************************************************************
var myObject = {
iAm : 'an object',
whatAmI : function(){
console.log('I am ' + this.iAm + "// this initialized from Literal");
}
}
myObject.whatAmI();
//************************************************************************************************************
//Using Contructor Function, Dynamic Binding
//************************************************************************************************************
function scripts(SName) {
this.sname= SName;
this.show=function(LName){
console.log("Script: "+this.sname+" type: "+LName+" //Using Constructor Function, Dynamic Binding");
};
}
var Scripts= new scripts('Javascript');
Scripts.show('text/javascript');
//************************************************************************************************************
//Using Literal
//change made to object literal effects change across the entire script
//************************************************************************************************************
var litObject = {
propertyName: "This is First Property"
};
console.log('change made to object literal effects change across the entire script');
console.log("\npropertyName: "+litObject.propertyName+" //Object Literal property change, effect all script...