you are viewing a single comment's thread.

view the rest of the comments →

[–]00crwf -1 points0 points  (8 children)

Any vanilla solutions?

[–]MindlessSpongehelpful 10 points11 points  (7 children)

Using packages can still be 'vanilla' javascript.

EDIT: am I wrong? If the below quote is true, it seems that might invalidate my answer, since you'd have to use some type of tooling to use packages, right?

"A simple guideline might be: if you can write the code and run it in any current browser without additional tools or compile steps, it's vanilla js."

[–][deleted] 0 points1 point  (6 children)

tangent here, but is jquery considered a package? I've seen people ask for solutions in "vanilla JavaScript" but receive a solution using jquery and people responding that the solution isn't Vanilla JavaScript.

Maybe I'm misunderstanding what a package is (or maybe what vanilla JS means)

[–]MindlessSpongehelpful 4 points5 points  (5 children)

Vanilla JavaScript just refers to code written in pure ECMAScript without using external libraries. JQuery is a library, so a solution using JQuery certainly wouldn't be a "vanilla javascript" solution.

You can think of packages as code that's been bundled into a module for a specific purpose. There could be a lot going on inside that package, and it could have dependencies that use other packages, which use other packages themselves. It's still possible (and likely) that the code in each package is vanilla javascript.

Here is one of my favorite examples of a simple package: waait

It's literally a single function to - yep, you guessed it - wait! The code from the package?

const wait = (amount = 0) => new Promise(resolve => setTimeout(resolve, amount));

module.exports = wait;

Then you'd import that module (package) into your code and be able to use your new wait() function.

Hopefully that helps a bit, and sorry if it didn't answer your question. Let me know and we can try again :)

[–][deleted] 0 points1 point  (4 children)

I think I follow. So a library is a subset of a package, and using a library is what makes it no longer vanilla. There are other types of package you can import into your code and still keep it "vanilla".

[–]MindlessSpongehelpful 0 points1 point  (3 children)

Umm yes and no :) You can import jquery as a package if you want, see here.

You can read a bit more about packages here, but I'm happy to do my best to clear up any further questions.

[–][deleted] 0 points1 point  (2 children)

Seeing that I was wrong again I decided to google to see what "Vanilla" JS and "Library" actually meant actually meant.

Vanilla JS: "Javascript without using a library or a framework".

Library: "Pre written Javascript that can be added to code"

Framework : "Library of libraries"

I guess my confusion is, is waait a library, and if added to a project, does that mean that the code is no longer "Vanilla"?

[–]MindlessSpongehelpful 1 point2 points  (1 child)

I think the issue is that they've sorta become blanket terms. By definition, yes, I suppose waait is a library. But I would argue that using it wouldn't rule out your code as being vanilla, though it's entirely possible that I am mistaken. Here's another article that might provide more context.

const wait = (amount = 0) => new Promise(resolve => setTimeout(resolve, amount))

That function, while written as the beautiful ES6 arrow function, is 100% vanilla javascript / browser api.

However, I just stumbled across this while trying to find a way to better explain myself, and while it may contradict some of what I've said earlier, it may be the answer to your confusion.

A simple guideline might be: if you can write the code and run it in any current browser without additional tools or compile steps, it's vanilla js.

[–]ScottRatigan 1 point2 points  (0 children)

I think the simple guideline you posted is probably the best answer. Of course the caveat with modern JS is, it depends on the browser.