js basics

fn as objects

by bhupendra negi

JavaScript

/*function rect(x,y)
{
    this.width = x // deafult
    this.length = y
    this.getArea = function () { return this.length * this.width }
}


var obj1 = new rect(10,5);
console.log(obj1.getArea());
console.log(obj1);
*/
function emp()
{
 this.empno = 18540;
 this.ename = "k8q";
 this.salary = 10; 
 this.email = "[email protected]";   
 this.validateEmail = function() 
 {
     var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(this.email);
 };
 this.salaryincrement = function(x)
 {
     this.salary += x;
     return this.salary;
 }
 
}

var obj3 = new emp();
console.log(obj3.validateEmail());
console.log(obj3.salaryincrement(10));