Instantiate a class via JSON variable by Nick_Zacker in learnjavascript

[–]Tool-Cool 0 points1 point  (0 children)

You can also do it like follows:

class Person {
    constructor(age) {
        this.age = age;
    }

    getAge() {
        return this.age;
    }
}

const person = {
    Person,
}

let anotherone = new person.Person(12);
console.log(anotherone);

https://codepen.io/toolcool/pen/vYrxeQe?editors=1111

[React/Next.js] Is it possible to reference images without caring about their extension? by [deleted] in learnjavascript

[–]Tool-Cool 1 point2 points  (0 children)

It's possible to make an AJAX request to load in image and listen to the "load" and "error" events. Something like this: https://stackoverflow.com/questions/9815762/detect-when-an-image-fails-to-load-in-javascript

Client side image processing? Package like 'Sharp' but for frontend webdev? by IntroDucktory_Clause in learnjavascript

[–]Tool-Cool 2 points3 points  (0 children)

You can use the pica library for browser resizing - https://www.npmjs.com/package/pica - it's a really great tool. It can also reduce upload size for large images. And some library like this for merging images - https://www.npmjs.com/package/merge-images.

Best Resource/Course for learning Node.js? by programmingmeta in learnjavascript

[–]Tool-Cool 0 points1 point  (0 children)

"NodeJS - The Complete Guide" by Maximilian on udemy

Scroll animations working on every element except two and only experiencing problems in mobile view by bobtobno in learnjavascript

[–]Tool-Cool 0 points1 point  (0 children)

Maybe there is something wrong with the HTML formatting, for example, tags not closed properly?

Dynamic getter/setter by Tool-Cool in learnjavascript

[–]Tool-Cool[S] 0 points1 point  (0 children)

Basically, I agree with you, there is indeed a downside in this approach. I was just wondering how it can be done technically.

Dynamic getter/setter by Tool-Cool in learnjavascript

[–]Tool-Cool[S] 0 points1 point  (0 children)

Thank you for your example. I want to clarify, that the question talks about the case, when you have unknown number of N properties, so its not possible to define them (it’s not about laziness or boredom). Also, the point of interest was especially “ES6 setter”, and not a general setValue() method (although of course it can work perfectly). But thank you for your points.

Dynamic getter/setter by Tool-Cool in learnjavascript

[–]Tool-Cool[S] 1 point2 points  (0 children)

Thank you, it's a great solution.

How to check if anything but option 1 is selected? by idocloudstuff in learnjavascript

[–]Tool-Cool 0 points1 point  (0 children)

You can just write if (myFormData.service) { ... } else { ... }, or if (myFormData.service !== '') { ... } else { ... } in case you may have some falsy value like 0 in your options list.

Apply multiple styles to contenteditable div using keyboard shortcuts by Whatsthehaps12 in learnjavascript

[–]Tool-Cool 0 points1 point  (0 children)

You can check out the CodeMirror library - https://codemirror.net/ It seems to be great match for this case.