JS Bin
// source https://jsbin.com/fakoqovofu
var bob = {
firstName: 'Bob',
lastName: 'Smith',
phoneNumber: '604-604-6040',
email: 'bob@redacademy.com'
};
for (var prop in bob) {
console.log(bob[prop]);
}
// Making new objects (object literal)
var myTruck = {
make : 'Ford',
model : 'Ranger',
year : 2000
};
// console.log(myTruck);
// OR TRY This
var myCar = new Object(); //Make an empty object
// Now lets add some properties
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;
// console.log(myCar);
// constructor
//Below is a function for the object type (name, properties, methods)
function Car(make, model, year){
this.make = make;
this.model = model;
this.year = year;
}
//Create (instantiate) a new object
var roseCar = new Car('Tesla','Model X', 2017);
var yourCar = new Car('Volkswagon', 'Golf', 1990);
// console.log(roseCar);
// console.log(yourCar);
<!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">
var bob = {
firstName: 'Bob',
lastName: 'Smith',
phoneNumber: '604-604-6040',
email: 'bob@redacademy.com'
};
for (var prop in bob) {
console.log(bob[prop]);
}
// Making new objects (object literal)
var myTruck = {
make : 'Ford',
model : 'Ranger',
year : 2000
};
// console.log(myTruck);
// OR TRY This
var myCar = new Object(); //Make an empty object
// Now lets add some properties
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;
// console.log(myCar);
// constructor
//Below is a function for the object type (name, properties, methods)
function Car(make, model, year){
this.make = make;
this.model = model;
this.year = year;
}
//Create (instantiate) a new object
var roseCar = new Car('Tesla','Model X', 2017);
var yourCar = new Car('Volkswagon', 'Golf', 1990);
// console.log(roseCar);
// console.log(yourCar);
</script>
<script id="jsbin-source-javascript" type="text/javascript">var bob = {
firstName: 'Bob',
lastName: 'Smith',
phoneNumber: '604-604-6040',
email: 'bob@redacademy.com'
};
for (var prop in bob) {
console.log(bob[prop]);
}
// Making new objects (object literal)
var myTruck = {
make : 'Ford',
model : 'Ranger',
year : 2000
};
// console.log(myTruck);
// OR TRY This
var myCar = new Object(); //Make an empty object
// Now lets add some properties
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;
// console.log(myCar);
// constructor
//Below is a function for the object type (name, properties, methods)
function Car(make, model, year){
this.make = make;
this.model = model;
this.year = year;
}
//Create (instantiate) a new object
var roseCar = new Car('Tesla','Model X', 2017);
var yourCar = new Car('Volkswagon', 'Golf', 1990);
// console.log(roseCar);
// console.log(yourCar);
</script></body>
</html>