r/javascript • • Dec 16 '18

Coming from Python to JS NSFW

const print = console.log

I found my safe space.

607 Upvotes

156 comments sorted by

View all comments

84

u/uberpwnzorz Dec 17 '18

you need to use bind so the log function keeps the context of console.

const print = console.log.bind(console)

0

u/[deleted] Dec 17 '18

[deleted]

2

u/uberpwnzorz Dec 18 '18

it's a prototype function, technically. MDN calls it a function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype

Classes and Methods are just sugar for prototype in JavaScript