working link=>https://stackblitz.com/edit/js-ms1npr
function emp()
{
console.log("called");
}
emp.prototype.getEmpSalary=function(salary)
{
const totalSalary=salary*12;
return totalSalary;
}
emp.prototype.empType=function(salary,type)
{
let salaryObject={};
switch(type)
{
case "it" :
salaryObject.type="it emp";
salaryObject.salary=salary*12;
break;
case "others" :
salaryObject.type="others emp";
salaryObject.salary=salary*12;
break;
}
return salaryObject;
}
var manish=new emp();
function callEmp(s)
{
//invoke a function emp using call
console.log(emp.prototype.getEmpSalary.call(this,s));
//invoke a function emp using apply
console.log( emp.prototype.empType.apply(this,[2000,"it"]));
}
callEmp(20000);
//deference between call and apply call work on number of argruments passed while apply works on array
//object assign extending object with new properties
function languageType()
{
this.name="java";
this.type="Object Oriented";
}
var java=Object.assign(languageType,{version:8});
console.log(java.version);
//more details
//https://googlechrome.github.io/samples/object-assign-es6/
Comments
Post a Comment