Skip to content

Instantly share code, notes, and snippets.

View gpDA's full-sized avatar
🏠
Working from home

GP LEE gpDA

🏠
Working from home
View GitHub Profile
// A constructor for defining new cars
function Car (options) {
// some defaults
this.doors = options.doors || 4;
this.state = options.state || "brand new";
this.color = options.color || "silver";
}
// A constructor for defining new trucks
function Car( model, year, miles ) {
this.model = model;
this.year = year;
this.miles = miles;
this.toString = function () {
return this.model + " has done " + this.miles + " miles";
};
}
let person2 = Object.assign({}, new Person('SJ', 'Steven', 32, 'male', ['music', 'skiing']))
console.log(person2)
// { name: { first: 'SJ', last: 'Steven' }, age: 32, gender: 'male' }
person1.age = 50;
person1.gender = 'female';
console.log(person1);
// Person {
// name: { first: 'Bob', last: 'Smith' },
// age: 50,
// gender: 'female'
//}
function Person(first, last, age, gender, interests) {
// property and method definitions
this.name = {
'first': first,
'last' : last
};
this.age = age;
this.gender = gender;
//...see link in summary above for full definition
setTimeout(() => { console.log('helloworld') }, 1000);
setTimeout(function() {
console.log('helloworld');
}, 10000);
setTimeout('doSomething(someVar)', 10000);
function doSomething(someVar) {
console.log(someVar)
}
function student(...args){
const inputArray = args // [ 'hello', 'world', 'people' ]
this.fname = inputArray[0];
if (inputArray.length === 3) {
this.mname = inputArray[1];
this.lname = inputArray[2];
} else {
this.mname = '';
<html>
<head>
<script type = "javascript" src = "TeamA1.js"></script>
<script type = "javascript" src = "TeamA2.js"></script>
</head>
<body>
<div id = "resultDiv"></div>
<script>
document.getElementById("resultDiv").innerHTML =
new student("Rajendra", "prasad").getFullName();