Skip to content

Instantly share code, notes, and snippets.

@mrDarcyMurphy
Last active December 22, 2015 09:49
Show Gist options
  • Save mrDarcyMurphy/6454743 to your computer and use it in GitHub Desktop.
Save mrDarcyMurphy/6454743 to your computer and use it in GitHub Desktop.
Breaking down various function properties when they're called in various ways.
var global = this
// Terminal Colors
// FG
// \033[30m black
// \033[31m red
// \033[32m green
// \033[33m yellow
// \033[34m blue
// \033[35m purple
// \033[36m teal
// BG
// \033[40m black
// \033[41m red
// \033[42m green
// \033[43m yellow
// \033[44m blue
// \033[45m purple
// \033[46m teal
// \033[47m white
// FG Bold
// \033[90m black
// \033[91m red
// \033[92m green
// \033[93m yellow
// \033[94m blue
// \033[95m purple
// \033[96m teal
// BG Bold
// \033[100m black
// \033[101m red
// \033[102m green
// \033[103m yellow
// \033[104m blue
// \033[105m purple
// \033[106m teal
// \033[107m white
var reset = '\033[0m'
var yes = '\033[32m' + '✔' + '\033[92m'
var no = ' ' + '\033[90m'
var grey = '\033[90m'
function title() {
var args = Array.prototype.slice.call(arguments)
args[0] = '\n\n\033[34m' + args[0]
args.push(reset)
console.log.apply(console.log, args)
}
function info() {
var args = Array.prototype.slice.call(arguments)
args[0] = '\033[90m ' + args[0] + reset
args.push(reset)
console.log.apply(console.log, args)
}
function test() {
var args = Array.prototype.slice.call(arguments)
args[0] = args[0] ? yes : no
args.push(reset)
console.log.apply(console.log, args)
}
function effen(arg) {
// this
test(!!this, 'this')
info('this.name', this.name)
info('typeof this', typeof this)
test(this == global, 'this == global')
test(this == effen, 'this == effen')
info('this.name', this.name ? this.name : '')
test(this._prop, 'this._prop')
test(this.prototype, 'this.prototype')
test(this.prototype && this.prototype._protoProp, 'this.prototype._protoProp')
test(this._protoProp, 'this._protoProp')
console.log('')
// effen
test(!!effen, 'effen')
info('effen.name', effen.name ? effen.name : '')
test(effen._prop, 'effen._prop')
test(effen._protoProp, 'effen._protoProp')
test(effen.prototype, 'effen.prototype')
test(effen.prototype && effen.prototype._protoProp, 'effen.prototype._protoProp')
console.log('')
// constructor
test(!!this.constructor, 'this.constructor')
info('this.constructor.name', this.constructor.name)
test(this.constructor == effen, 'this.constructor == effen')
test(this.constructor._prop, 'this.constructor._prop')
test(this.constructor.prototype, 'this.constructor.prototype')
test(this.constructor.prototype && this.constructor.prototype._protoProp, 'this.constructor.prototype._protoProp')
test(this.constructor._protoProp, 'this.constructor._protoProp')
console.log('')
// argument
test(!!arg, 'arg')
if (!!arg) {
info('typeof arg', !!arg && typeof arg || '')
info('arg.name', arg && arg.name ? arg.name : '')
test(arg && arg._prop, 'arg._prop')
test(arg && arg.prototype, 'arg.prototype')
test(arg && arg.prototype && arg.prototype._protoProp, 'arg.prototype._protoProp')
test(arg && arg._protoProp, 'arg._protoProp')
test(arg == this, 'arg == this')
test(arg == effen, 'arg == effen')
test(arg == global, 'arg == global')
}
console.log('\033[90m' + '--')
return effen
}
effen._prop = 'this is _prop'
effen.prototype._protoProp = 'this is _protoProp'
// Evaluating
title('effen()')
effen()
title('effen(this)')
effen(this)
title('new effen()')
new effen()
title('new effen(this)')
new effen(this)
title('effen(effen)')
effen(effen)
title('new effen(effen)')
new effen(effen)
title('effen(new effen())')
effen(new effen())
title('new effen(new effen())')
new effen(new effen())
title('effen(new effen)')
effen(new effen)
title('new effen(new effen)')
new effen(new effen)
title('new effen(new effen())')
new effen(new effen())
title('effen.call()')
effen.call()
title('effen.call(this)')
effen.call(this)
title('effen.call(effen)')
effen.call(effen)
title('effen.call(new effen)')
effen.call(new effen)
title('effen.call(new effen, effen)')
effen.call(new effen, effen)
title('effen.call(new effen, new effen)')
effen.call(new effen, new effen)
title('effen.call(new effen, new effen())')
effen.call(new effen, new effen())
title('(effen)("test")');
(effen)('test')
effen()
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
effen(this)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg object
arg.name
arg._prop
arg.prototype
arg.prototype._protoProp
arg._protoProp
arg == this
arg == effen
✔ arg == global
--
new effen()
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
new effen(this)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg object
arg.name
arg._prop
arg.prototype
arg.prototype._protoProp
arg._protoProp
arg == this
arg == effen
✔ arg == global
--
effen(effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
new effen(effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
effen(new effen())
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
new effen(new effen())
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
effen(new effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
new effen(new effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
new effen(new effen())
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
arg == this
✔ arg == effen
arg == global
--
effen.call()
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
effen.call(this)
✔ this
this.name undefined
typeof this object
✔ this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
effen.call(effen)
✔ this
this.name effen
typeof this function
this == global
✔ this == effen
this.name effen
✔ this._prop
✔ this.prototype
✔ this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Function
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
effen.call(new effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name effen
typeof this function
this == global
✔ this == effen
this.name effen
✔ this._prop
✔ this.prototype
✔ this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Function
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
effen.call(new effen, effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name effen
typeof this function
this == global
✔ this == effen
this.name effen
✔ this._prop
✔ this.prototype
✔ this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Function
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
✔ arg == this
✔ arg == effen
arg == global
--
effen.call(new effen, new effen)
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name effen
typeof this function
this == global
✔ this == effen
this.name effen
✔ this._prop
✔ this.prototype
✔ this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Function
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
✔ arg == this
✔ arg == effen
arg == global
--
effen.call(new effen, new effen())
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
✔ this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name effen
✔ this.constructor == effen
✔ this.constructor._prop
✔ this.constructor.prototype
✔ this.constructor.prototype._protoProp
this.constructor._protoProp
arg
--
✔ this
this.name effen
typeof this function
this == global
✔ this == effen
this.name effen
✔ this._prop
✔ this.prototype
✔ this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Function
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg function
arg.name effen
✔ arg._prop
✔ arg.prototype
✔ arg.prototype._protoProp
arg._protoProp
✔ arg == this
✔ arg == effen
arg == global
--
(effen)("test")
✔ this
this.name undefined
typeof this object
this == global
this == effen
this.name
this._prop
this.prototype
this.prototype._protoProp
this._protoProp
✔ effen
effen.name effen
✔ effen._prop
effen._protoProp
✔ effen.prototype
✔ effen.prototype._protoProp
✔ this.constructor
this.constructor.name Object
this.constructor == effen
this.constructor._prop
✔ this.constructor.prototype
this.constructor.prototype._protoProp
this.constructor._protoProp
✔ arg
typeof arg string
arg.name
arg._prop
arg.prototype
arg.prototype._protoProp
arg._protoProp
arg == this
arg == effen
arg == global
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment