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

22

u/BloodAndTsundere Dec 16 '18

I actually kind of like this because I always manage a typo when I type 'console.log'. I get a lot of 'cosnole.log'. I think I'm much more consistent typing 'print'.

26

u/Earhacker Dec 16 '18

VS Code, Atom and the like usually have a snippet that autocompletes when you just type "log".

0

u/[deleted] Dec 16 '18

[deleted]

33

u/Earhacker Dec 16 '18

You could go to Menu -> Preferences -> User Snippets -> JavaScript and add this to the file:

"Print to console": {
    "prefix": "print",
    "body": [
        "console.log('$1');",
        "$2"
    ],
    "description": "Log output to console"
}

And now every time you type "print" in a JS file it will autocomplete to "console.log()" with your cursor between the brackets.

Safe space safely restored!

0

u/[deleted] Dec 16 '18

[deleted]

3

u/[deleted] Dec 17 '18

I did the same thing when I started learning react and found a nifty autocomplete vscode addon. I thought “wait, how are these snippets generated?”

Somehow it never occurred to me that I could write boilerplate snippets for other languages until this point.

Super handy way to cut down on typing and dumb mistakes.

2

u/mrbojingle Dec 17 '18

Right!? It's so useful. I've got my most common stuff all made into snippets that are context sensitive (using some regex magic), so if I hit { inside an object it gives me `: { }`, in a function `const = {}`, in an array or parens {}. It's pretty sweet.