Skip to content

Instantly share code, notes, and snippets.

function a( ) {
var myvar = 2
function b() {
console.log(myvar);
}
b( );
}
var myvar = 1;
// Let's assume we have object o, with its own properties a and b:
// {a: 1, b: 2}
// o.[[Prototype]] has properties b and c:
// {b: 3, c: 4}
// Finally, o.[[Prototype]].[[Prototype]] is null.
// This is the end of the prototype chain as null,
// by definition, null has no [[Prototype]].
// Thus, the full prototype chain looks like:
// {a:1, b:2} ---> {b:3, c:4} ---> null
var o = {
a: 2,
m: function(b){
return this.a + 1;
}
};
var o = {
a: 2,
m: function(b){
return this.a + 1;
}
};
console.log(o.m()); // 3
// When calling o.m in this case, 'this' refers to o
var a = ["yo", "whadup", "?"];
// Arrays inherit from Array.prototype
// (which has methods like indexOf, forEach, etc.)
// The prototype chain looks like:
// a ---> Array.prototype ---> Object.prototype ---> null
function greet() {
console.log('hi')
}
function greet() {
console.log('hi')
}
greet.language = 'english'
console.log(greet.language)
// => 'english'
class Person {
constructor(firstname, lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
greet () {
return 'hi ' + firstname;
}
}
class InformalPerson extends Person {
constructor(firstname, lastname) {
super(firstname, lastname);
}
greet () {
return 'Yo ' + firstname;
}
}
@egrueter-dev
egrueter-dev / function-constructors-1.js
Last active June 27, 2016 00:47
Function Constructors
var john = new Person();
function Person() {
this.firstname = ‘John’
this.lastname = ‘Doe’
}