Skip to content

Instantly share code, notes, and snippets.

@eshrinivasan
Last active January 11, 2022 06:16
Show Gist options
  • Save eshrinivasan/0f6d38562a65fe2a7fe40606ce1d7940 to your computer and use it in GitHub Desktop.
Save eshrinivasan/0f6d38562a65fe2a7fe40606ce1d7940 to your computer and use it in GitHub Desktop.
Interview code check 2022
function Human(name, age){
this.name = name;
this.age = age;
}
Human.prototype.goestoWork = function(){
return true;
}
function Employee(name, age, empid, gender){
Human.call(this, name, age);
this.empId = empid;
this.gender = gender;
}
Employee.prototype = Object.create(Human.prototype);
Employee.constructor = Employee;
Employee.prototype.finishesProject = function(){
return true;
}
function Avatar(name, age, empid, gender){
Employee.call(this, name, age, empid, gender);
this.canbecomeDad = function(){
return true;
}
}
Avatar.prototype = Object.create(Employee.prototype);
Avatar.constructor = Avatar;
var senthil = new Avatar("Senth", '40', "A123", "M" );
console.log(senthil.empId);
console.log(senthil.gender);
console.log(senthil.name);
console.log(senthil.canbecomeDad());
console.log(senthil.age);
console.log(senthil.goestoWork());
console.log(senthil.finishesProject());
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function Human(name, age){
this.name = name;
this.age = age;
}
Human.prototype.goestoWork = function(){
return true;
}
function Employee(name, age, empid, gender){
Human.call(this, name, age);
this.empId = empid;
this.gender = gender;
}
Employee.prototype = Object.create(Human.prototype);
Employee.constructor = Employee;
Employee.prototype.finishesProject = function(){
return true;
}
function Avatar(name, age, empid, gender){
Employee.call(this, name, age, empid, gender);
this.canbecomeDad = function(){
return true;
}
}
Avatar.prototype = Object.create(Employee.prototype);
Avatar.constructor = Avatar;
var senthil = new Avatar("Senth", '40', "A123", "M" );
console.log(senthil.empId);
console.log(senthil.gender);
console.log(senthil.name);
console.log(senthil.canbecomeDad());
console.log(senthil.age);
console.log(senthil.goestoWork());
console.log(senthil.finishesProject());
</script>
<script id="jsbin-source-javascript" type="text/javascript">function Human(name, age){
this.name = name;
this.age = age;
}
Human.prototype.goestoWork = function(){
return true;
}
function Employee(name, age, empid, gender){
Human.call(this, name, age);
this.empId = empid;
this.gender = gender;
}
Employee.prototype = Object.create(Human.prototype);
Employee.constructor = Employee;
Employee.prototype.finishesProject = function(){
return true;
}
function Avatar(name, age, empid, gender){
Employee.call(this, name, age, empid, gender);
this.canbecomeDad = function(){
return true;
}
}
Avatar.prototype = Object.create(Employee.prototype);
Avatar.constructor = Avatar;
var senthil = new Avatar("Senth", '40', "A123", "M" );
console.log(senthil.empId);
console.log(senthil.gender);
console.log(senthil.name);
console.log(senthil.canbecomeDad());
console.log(senthil.age);
console.log(senthil.goestoWork());
console.log(senthil.finishesProject());
</script></body>
</html>
@eshrinivasan
Copy link
Author

eshrinivasan commented Dec 11, 2020

var promise = new Promise(function(resolve, reject) {
  // do a thing, possibly async, then…

request.get(options, function(err, resp, body) {
            if (err) {
                 reject(Error(err+"It broke"));
            } else {
                 resolve("Stuff worked!");
            }
        });
});

promise.then(function(result) {
  console.log(result); // "Stuff worked!"
}, function(err) {
  console.log(err); // Error: "It broke"
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment