Created
June 14, 2018 00:03
-
-
Save BernieGoll/33582e3da6befad66ee83124daa2eb23 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hagalof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> | |
// NEW PROBLEM -------------- | |
/* | |
let person= | |
{ | |
firstName: "bern", | |
lastName: "goll", | |
fullName: function() | |
{ | |
return this.firstName + " "+ this.lastName; | |
} | |
} | |
console.log("The person's full name is: "+person.fullName); | |
*/ | |
// NEW PROBLEM ------------------ | |
// Creating a CONSTRUCTOR | |
/* | |
function Dog() | |
{ | |
this.name = "Spot"; | |
this.color = "Yellow"; | |
this.numLegs = 4; | |
} | |
// Using Constructor to create an OBJECT | |
let myDog = new Dog(); | |
// now an Object is created represented by instance variable 'myDog' | |
console.log(myDog.name); //output: "Spot" | |
// now change myDog name | |
myDog.name = 'Sophie'; | |
console.log(myDog.name); | |
console.log(myDog instanceof Dog); | |
// ** you can see, with INSTANCEOF operator, it's true the 'myDog' object derived from | |
// Constructor 'Dog' | |
*/ | |
// NEW PROBLEM ---------------- | |
// Creating Constuctor with Parameters/Arguements | |
/* | |
function Dog(name, color) | |
{ | |
this.name = name; | |
this.color = color; | |
this.numLegs = 4; | |
} | |
const terrier = new Dog("Rudie", "Brownish"); | |
console.log(terrier.name, terrier.color, terrier.numLegs); | |
*/ | |
//NEW PROBLEM ---------------- | |
// Zach's way to create a CLASS so an Object is created vs. from Constructor itself | |
/* | |
class Dog { | |
constructor (name, color, numLegs) { | |
this.name = name; | |
this.color = color; | |
this.numLegs = numLegs; | |
} | |
printDogName () { | |
console.log(this.name) | |
} | |
printDogColor () { | |
console.log(this.color); | |
} | |
} | |
const dog = new Dog('Rudie', 'Brown', 4); | |
dog.printDogName(); | |
dog.printDogColor(); | |
console.log(dog.numLegs); | |
console.log(dog instanceof Dog); | |
*/ | |
//NEW PROBLEM -------------------- | |
// Understanding OWN PROPERTY | |
/* | |
function Bird(name) { | |
this.name = name; | |
this.numLegs = 2; | |
} | |
let canary = new Bird("Tweety"); | |
let ownProps = []; | |
for(let property in canary) | |
{ | |
if(canary.hasOwnProperty(property)) | |
{ | |
ownProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Understanding PROTOTYPE PROPERTIES | |
/* | |
function Dog(name) | |
{ | |
this.name = name; | |
} | |
Dog.prototype.numLegs =2; | |
const beagle = new Dog("Snoopy"); | |
console.log(beagle.numLegs); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Iterating over OWN and PROTOTYPE Properties | |
// This adds Own properties of beagle to array and adds Prototype props of Dog to array | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype.numLegs = 4; | |
let beagle = new Dog("Snoopy"); | |
let ownProps = []; | |
let prototypeProps = []; | |
// Add your code below this line | |
for(let property in beagle) | |
{ | |
if(beagle.hasOwnProperty (property)) | |
{ | |
ownProps.push(property); | |
} | |
else | |
{ | |
prototypeProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
console.log(prototypeProps); | |
*/ | |
/* | |
//NEW PROBLEM ------------------ | |
// Understanding the Constructor Property | |
function Dog(name) { | |
this.name = name; | |
} | |
function joinDogFraternity(candidate) { | |
if(candidate.constructor ===Dog) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
console.log(Dog.constructor ===Dog); //output: false - because Dog not a | |
// property of Dog (if I created a 'dog' instance and asked, it would be true) | |
*/ | |
//NEW PROBLEM ------------------ | |
// Changing Prototype to a NEW OBJECT | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype = { | |
constructor:Dog, | |
numLegs: 2, | |
eat: function() | |
{ | |
console.log("nom nom nom"); | |
}, | |
describe: function() | |
{ | |
console.log("My name is "+ this.name); | |
} | |
}; | |
console.log(Dog.prototype.describe); //very conceptual exercise, not much to DISPLAY | |
*/ | |
//NEW PROBLEM ----------------------THIS IS WAY OUT THERE---- | |
// RECURSION - all you should try to know | |
/* | |
function factorial( n ) | |
{ | |
if ( n === 1 ) | |
{ | |
return 1; | |
} | |
return n * factorial( n - 1 ); | |
} | |
*/ | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// NEW PROBLEM -------------- | |
/* | |
let person= | |
{ | |
firstName: "bern", | |
lastName: "goll", | |
fullName: function() | |
{ | |
return this.firstName + " "+ this.lastName; | |
} | |
} | |
console.log("The person's full name is: "+person.fullName); | |
*/ | |
// NEW PROBLEM ------------------ | |
// Creating a CONSTRUCTOR | |
/* | |
function Dog() | |
{ | |
this.name = "Spot"; | |
this.color = "Yellow"; | |
this.numLegs = 4; | |
} | |
// Using Constructor to create an OBJECT | |
let myDog = new Dog(); | |
// now an Object is created represented by instance variable 'myDog' | |
console.log(myDog.name); //output: "Spot" | |
// now change myDog name | |
myDog.name = 'Sophie'; | |
console.log(myDog.name); | |
console.log(myDog instanceof Dog); | |
// ** you can see, with INSTANCEOF operator, it's true the 'myDog' object derived from | |
// Constructor 'Dog' | |
*/ | |
// NEW PROBLEM ---------------- | |
// Creating Constuctor with Parameters/Arguements | |
/* | |
function Dog(name, color) | |
{ | |
this.name = name; | |
this.color = color; | |
this.numLegs = 4; | |
} | |
const terrier = new Dog("Rudie", "Brownish"); | |
console.log(terrier.name, terrier.color, terrier.numLegs); | |
*/ | |
//NEW PROBLEM ---------------- | |
// Zach's way to create a CLASS so an Object is created vs. from Constructor itself | |
/* | |
class Dog { | |
constructor (name, color, numLegs) { | |
this.name = name; | |
this.color = color; | |
this.numLegs = numLegs; | |
} | |
printDogName () { | |
console.log(this.name) | |
} | |
printDogColor () { | |
console.log(this.color); | |
} | |
} | |
const dog = new Dog('Rudie', 'Brown', 4); | |
dog.printDogName(); | |
dog.printDogColor(); | |
console.log(dog.numLegs); | |
console.log(dog instanceof Dog); | |
*/ | |
//NEW PROBLEM -------------------- | |
// Understanding OWN PROPERTY | |
/* | |
function Bird(name) { | |
this.name = name; | |
this.numLegs = 2; | |
} | |
let canary = new Bird("Tweety"); | |
let ownProps = []; | |
for(let property in canary) | |
{ | |
if(canary.hasOwnProperty(property)) | |
{ | |
ownProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Understanding PROTOTYPE PROPERTIES | |
/* | |
function Dog(name) | |
{ | |
this.name = name; | |
} | |
Dog.prototype.numLegs =2; | |
const beagle = new Dog("Snoopy"); | |
console.log(beagle.numLegs); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Iterating over OWN and PROTOTYPE Properties | |
// This adds Own properties of beagle to array and adds Prototype props of Dog to array | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype.numLegs = 4; | |
let beagle = new Dog("Snoopy"); | |
let ownProps = []; | |
let prototypeProps = []; | |
// Add your code below this line | |
for(let property in beagle) | |
{ | |
if(beagle.hasOwnProperty (property)) | |
{ | |
ownProps.push(property); | |
} | |
else | |
{ | |
prototypeProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
console.log(prototypeProps); | |
*/ | |
/* | |
//NEW PROBLEM ------------------ | |
// Understanding the Constructor Property | |
function Dog(name) { | |
this.name = name; | |
} | |
function joinDogFraternity(candidate) { | |
if(candidate.constructor ===Dog) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
console.log(Dog.constructor ===Dog); //output: false - because Dog not a | |
// property of Dog (if I created a 'dog' instance and asked, it would be true) | |
*/ | |
//NEW PROBLEM ------------------ | |
// Changing Prototype to a NEW OBJECT | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype = { | |
constructor:Dog, | |
numLegs: 2, | |
eat: function() | |
{ | |
console.log("nom nom nom"); | |
}, | |
describe: function() | |
{ | |
console.log("My name is "+ this.name); | |
} | |
}; | |
console.log(Dog.prototype.describe); //very conceptual exercise, not much to DISPLAY | |
*/ | |
//NEW PROBLEM ----------------------THIS IS WAY OUT THERE---- | |
// RECURSION - all you should try to know | |
/* | |
function factorial( n ) | |
{ | |
if ( n === 1 ) | |
{ | |
return 1; | |
} | |
return n * factorial( n - 1 ); | |
} | |
*/ | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NEW PROBLEM -------------- | |
/* | |
let person= | |
{ | |
firstName: "bern", | |
lastName: "goll", | |
fullName: function() | |
{ | |
return this.firstName + " "+ this.lastName; | |
} | |
} | |
console.log("The person's full name is: "+person.fullName); | |
*/ | |
// NEW PROBLEM ------------------ | |
// Creating a CONSTRUCTOR | |
/* | |
function Dog() | |
{ | |
this.name = "Spot"; | |
this.color = "Yellow"; | |
this.numLegs = 4; | |
} | |
// Using Constructor to create an OBJECT | |
let myDog = new Dog(); | |
// now an Object is created represented by instance variable 'myDog' | |
console.log(myDog.name); //output: "Spot" | |
// now change myDog name | |
myDog.name = 'Sophie'; | |
console.log(myDog.name); | |
console.log(myDog instanceof Dog); | |
// ** you can see, with INSTANCEOF operator, it's true the 'myDog' object derived from | |
// Constructor 'Dog' | |
*/ | |
// NEW PROBLEM ---------------- | |
// Creating Constuctor with Parameters/Arguements | |
/* | |
function Dog(name, color) | |
{ | |
this.name = name; | |
this.color = color; | |
this.numLegs = 4; | |
} | |
const terrier = new Dog("Rudie", "Brownish"); | |
console.log(terrier.name, terrier.color, terrier.numLegs); | |
*/ | |
//NEW PROBLEM ---------------- | |
// Zach's way to create a CLASS so an Object is created vs. from Constructor itself | |
/* | |
class Dog { | |
constructor (name, color, numLegs) { | |
this.name = name; | |
this.color = color; | |
this.numLegs = numLegs; | |
} | |
printDogName () { | |
console.log(this.name) | |
} | |
printDogColor () { | |
console.log(this.color); | |
} | |
} | |
const dog = new Dog('Rudie', 'Brown', 4); | |
dog.printDogName(); | |
dog.printDogColor(); | |
console.log(dog.numLegs); | |
console.log(dog instanceof Dog); | |
*/ | |
//NEW PROBLEM -------------------- | |
// Understanding OWN PROPERTY | |
/* | |
function Bird(name) { | |
this.name = name; | |
this.numLegs = 2; | |
} | |
let canary = new Bird("Tweety"); | |
let ownProps = []; | |
for(let property in canary) | |
{ | |
if(canary.hasOwnProperty(property)) | |
{ | |
ownProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Understanding PROTOTYPE PROPERTIES | |
/* | |
function Dog(name) | |
{ | |
this.name = name; | |
} | |
Dog.prototype.numLegs =2; | |
const beagle = new Dog("Snoopy"); | |
console.log(beagle.numLegs); | |
*/ | |
//NEW PROBLEM --------------------- | |
// Iterating over OWN and PROTOTYPE Properties | |
// This adds Own properties of beagle to array and adds Prototype props of Dog to array | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype.numLegs = 4; | |
let beagle = new Dog("Snoopy"); | |
let ownProps = []; | |
let prototypeProps = []; | |
// Add your code below this line | |
for(let property in beagle) | |
{ | |
if(beagle.hasOwnProperty (property)) | |
{ | |
ownProps.push(property); | |
} | |
else | |
{ | |
prototypeProps.push(property); | |
} | |
} | |
console.log(ownProps); | |
console.log(prototypeProps); | |
*/ | |
/* | |
//NEW PROBLEM ------------------ | |
// Understanding the Constructor Property | |
function Dog(name) { | |
this.name = name; | |
} | |
function joinDogFraternity(candidate) { | |
if(candidate.constructor ===Dog) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
console.log(Dog.constructor ===Dog); //output: false - because Dog not a | |
// property of Dog (if I created a 'dog' instance and asked, it would be true) | |
*/ | |
//NEW PROBLEM ------------------ | |
// Changing Prototype to a NEW OBJECT | |
/* | |
function Dog(name) { | |
this.name = name; | |
} | |
Dog.prototype = { | |
constructor:Dog, | |
numLegs: 2, | |
eat: function() | |
{ | |
console.log("nom nom nom"); | |
}, | |
describe: function() | |
{ | |
console.log("My name is "+ this.name); | |
} | |
}; | |
console.log(Dog.prototype.describe); //very conceptual exercise, not much to DISPLAY | |
*/ | |
//NEW PROBLEM ----------------------THIS IS WAY OUT THERE---- | |
// RECURSION - all you should try to know | |
/* | |
function factorial( n ) | |
{ | |
if ( n === 1 ) | |
{ | |
return 1; | |
} | |
return n * factorial( n - 1 ); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment