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
var test = hello world |
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
var test = "hello world" |
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
function NEW(constructor, argsArray) { | |
var obj = {}; // step 1 | |
obj.__proto__ = constructor.prototype; // step 2 | |
constructor.apply(obj, argsArray); // step 3 | |
return obj; // step 4 | |
} | |
function Parent(name) { | |
this.name = name; | |
} | |
Parent.prototype.greet = function() { |
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
class Parent { | |
constructor(name) { | |
this.name = name; | |
} | |
greet() { | |
console.log(`Hi, I'm ${this.name}`); | |
} | |
} | |
var mom = new Parent("Mom"); |
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
class Parent { | |
constructor(name) { | |
this.name = name; | |
} | |
} | |
Parent.prototype.greet = () => { | |
console.log(`Hi, I'm ${this.name}`); | |
} | |
var mom = new Parent("Mom"); | |
mom.greet() // "Hi, I'm Mom" |
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
function Parent(name) { | |
var obj = Object.create(parentProto); | |
obj.name = name; | |
return obj | |
} | |
var parentProto = { | |
greet: function() { | |
console.log("hi, I'm " + this.name); | |
} | |
}; |
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
function buildObject(str) { | |
var newObj = {}; | |
var newKey, newVal; | |
var elstart = 1; | |
var elend = 1; | |
var contentsStr = str.substring(1,str.length-1); | |
contentsStr = contentsStr.trim(); | |
var contentsLength = contentsStr.length; | |
if (contentsLength === 0) { |
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
function buildObject(str) { | |
var newObj = {}; | |
var newKey, newVal; | |
var elstart = 1; | |
var elend = 1; | |
var contentsStr = str.substring(1,str.length-1); | |
contentsStr = contentsStr.trim(); | |
var contentsLength = contentsStr.length; | |
if (contentsLength === 0) { |
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
function buildObject(str) { | |
var newObj = {}; | |
var newKey, newVal; | |
var elstart = 1; | |
var elend = 1; | |
var contentsStr = str.substring(1,str.length-1); | |
contentsStr = contentsStr.trim(); | |
var contentsLength = contentsStr.length; | |
if (contentsLength === 0) { |
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
function buildObject(str) { | |
var newObj = {}; | |
var contents = str.substring(1, str.length-1).split(","); | |
if (!contents[0]) return newObj; | |
contents.forEach(function(keyValuePair) { | |
var keyAndValue = keyValuePair.split(":"); | |
var key = keyAndValue[0]; | |
var value = keyAndValue[1]; | |
newObj[key] = parse(value); // parse is a helper function |
OlderNewer