r/javascript • u/vladocar • Mar 06 '19
femtoJS - Really small JavaScript (ES6) library for DOM manipulation.
https://vladocar.github.io/femtoJS/32
u/kerbalspaceanus Mar 06 '19 edited Aug 12 '25
yam imminent retire juggle sink cats towering aspiring brave summer
This post was mass deleted and anonymized with Redact
2
u/vladocar Mar 06 '19
Hi I'm the author of this project. I think I need to clarify some things. First take a look into my previous project nanoJS https://github.com/vladocar/nanoJS/blob/master/src/nanoJS.js it takes more classical approach and works in IE9 and later.
Your concerns with femtoJS:
Pollutes the window object with global variables
It's true, it does. I know, this is not best practise. In the classical approach the methods are stored inside object.prototype and probably that is the best solution. I decided to store the methods inside the window object for a simple reason you can make jQuery like library with 2 lines of code.
I did this project to prove that you can make DOM manipulation library with very little code, yes and I sacrificed some common sense best practises in order to achieve this.
Why not use some VanillaJS? You can. But I find it repetitive declaring same stuff over and over again.
3
u/nhonx Mar 06 '19
Making a tiny version of jQuery doesnt mean that you need to simplize it in a totally different way like this. JQueryâs code structure and organization is (probably) best practice and following it certainly wonât make your âlibraryâ become heavier but more well-organizing. Weâre working in Javascript and namespace/variable name pollutions will be a big trouble to deal, especially when you want to make it a library to publish to everyone. At least, you should optimize the ways you naming in library, i.e add your prefix to namspace like âf$â, âfCssâ,âfHtmlâ,.... In addition, you said itâs a library that take advantage on ES6 and you used nothing from it, coding like exactly VanillaJs
1
u/kryptogalaxy Mar 06 '19
There are ... Lambdas. So that's basically all es6 /s
1
u/nhonx Mar 06 '19
Nope...i mean he didnt even use a signature feature of ES6 is class/object for code structure. Lambda is just a shorter ways to code and Iâm pretty sure that I can rewrite this library in VanillaJs within 0.3kb size increment
2
u/qashto Mar 06 '19
You should make a version that doesn't use the global window object. No one will want to use this library otherwise, doesn't matter how small it is if no one uses it.
6
2
u/AutoModerator Mar 06 '19
Project Page (?): https://github.com/vladocar/femtoJS
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/BenZed Mar 10 '19
When people say they hate javascript, I imagine libraries like this are what they have in mind.
0
u/simohayha Mar 06 '19
I don't want to sound like a jerk but this looks stupid as hell. Props to anyone who finds it useful
-6
u/Thaurin Mar 06 '19
Good! I've been wanting to get rid of jQuery, but I got so used to the (usually) shorter syntax!
24
Mar 06 '19 edited Mar 06 '19
const $ = el => document.querySelector(el)But really, just get rid of the cancer once and for all.. :D
Don't use that snippet in production for heavens sake5
Mar 06 '19
Problem I have with adding a shortcut like that is it's a bit misleading when switching between projects that have/don't have jQuery.
$('div') could be using jQuery or it may not - you have to understand the project and it's shortcuts.
For the sake of interoperability and muscle memory, I find it's simpler just to write
document.querySelectorin full.2
3
u/AwesomeInPerson Mar 06 '19
Then give it a different name?
const el = document.querySelector.bind(document) const els = selector => [...document.querySelectorAll(selector)]or something similar
1
u/Carradee Mar 06 '19
Or type it with a shortcut and use find & replace to expandâas a post-processor, if warranted.
-1
u/fucking_passwords Mar 06 '19
Or you know, you could just see what the value of
$is. Pretty easy to differentiate ajQueryinstance from this function.2
0
0
Mar 06 '19
[deleted]
11
u/Thaurin Mar 06 '19
Can you explain why, so that I can learn something?
1
Mar 06 '19
- He's applying shit to the global scope without consideration
- He's Mixing ES5 + ES6 and not transpiling it. defuck?
- He's not using a linter (fugly code)
Probably more stuff I've forgot :-D
28
u/envis10n Mar 06 '19
God forbid someone writes something at their skill level and doesn't know everything. The post above has a breakdown of issues in detail, and strays from attempting to insult the writer by pointing out their code is "fugly".
I hope others see this post of yours and look back on it when writing criticism for another's code, as a good example of how not to write constructive criticism.
2
Mar 06 '19
Sorry for my harsh words. I had 1 minute on the toilet-break :-D
Tho, someone had to point it out in order for the author to make sure he uses eslint on his next project :D
But yeah, your right. I could have done it in a nicer way (a)
2
u/envis10n Mar 06 '19
Thank you.
I don't use linters for my projects because I don't like how annoyingly perfect it wants everything. My code is generally readable without linting.
You don't need to lint to have effective or readable code.
Would I recommend it for someone that has bad writing habits? Yes. It's a good tool for encouraging better writing.
I assume this is what you mean when you talk about someone pointing it out so the author uses eslint next time.
2
u/troglo-dyke Mar 06 '19
For personal projects I'll agree that it's not necessary (although I do because I cba to manually reformat when refactoring), but anything which someone else will potentially contribute to you definitely should - because you don't know what kind of code those monkeys are going to write
3
Mar 06 '19
Yes!! I actually wasn't using a linter for the longest time. But I've always been a "code-nazi", at least that's what my co-workers call me :D
I used to hate linters (because of the weird configs, looking at you airbnb), but when I found StandardJS I haven't looked back. It was nearly 95% of what my code already looked like. just minor things to keep a standard
And honestly, I would never go back. It really catches everything, all the weird spaces that VSC adds and all of it <3
So yes. if you do know your code. Do whatever you please. If you don't know it, or have to share codebase with others. Please for the love of god, just pick one and stick with it.
that's my actual two cents on the case ;)
1
u/envis10n Mar 06 '19
Ah, yes. Working with others is definitely a good use case for linters. Keeping a standard is important when sharing. I don't normally work with others so I don't experience this issue. Thanks for that
-12
u/ForScale Mar 06 '19
Found the author!
13
u/envis10n Mar 06 '19
Heh, no. I just find it annoying that people would rather simply dump on another person's work than provide actually constructive criticism.
3
u/ForScale Mar 06 '19
Yeah, was just being cheeky. :)
I agree, constructive criticism is better than simply trashing.
0
Mar 06 '19
[deleted]
21
u/envis10n Mar 06 '19
Just wanted to say that your (actual) constructive criticism is refreshing to see.
Not everyone is at the same level in terms of skill and knowledge, so it's nice to see the actual issues pointed out rather than simply saying "it sucks".
13
u/ScientificBeastMode strongly typed comments Mar 06 '19 edited Mar 07 '19
âWould rather just use the vanilla DOM API and know nothing is missing.â
This is so important. There is absolutely nothing worse than building half of a web application, and then realizing your primary framework simply cannot accommodate a key feature that would ordinarily be available to you with vanilla JS.
This is especially true for a DOM manipulation framework, where bypassing the frameworkâs API to handle edge cases will likely lead to âmultiple sources of truth,â along with a cascading series of bugs down the road.
For this reason, itâs often much smarter to go with one of the popular frameworks on the market. React, Angular, jQuery, Vue, and so many more to choose from. Might as well use something thatâs well-maintained and well-documented.
That being said, I think itâs awesome for people to try building a comprehensive framework for DOM manipulation, or at least a working library to streamline it. It will definitely help clarify the problems all these frameworks are aiming to solve.
I have to say... coming from a guy who has tried earnestly to reinvent the wheel here, itâs so much better to let the pros handle it.
5
22
u/nwsm Mar 06 '19
Writing something amateur isnât embarrassing
8
u/Mestyo Mar 06 '19
Not in and by itself, no, but publishing it for others to use does make it kind of embarrassing.
16
u/envis10n Mar 06 '19
If you don't publish it, how are you supposed to get feedback and criticism? If only there was a magical portal for uploading your code in a public domain for others to see, use, and review...
It's not embarrassing to learn and grow. Every single programmer started out at the same place.
5
u/Mestyo Mar 06 '19
I agree, but this project is clearly presented as a product and not a learning experiment.
5
Mar 06 '19
I think he was hinting on that the user posted a separate post instead of posting in the weekly WTF wednesday thread, where we all gladly review each other without being _too_ critical
However, posting it like this might occur some harsh critisism (As you know, I'm one of them :D)
Cheers again mate <3
1
0
0
1
0
4
29
u/ConnectBoysenberry Mar 06 '19
var offset = (v) => {for (let i of s) offset = i.getBoundingClientRect(); return this}killed me.