« first day (4600 days earlier)      last day (570 days later) » 

00:22
@VLAZ unless ethically, of course.
How can you go wrong?
hmm... I wonder
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
yup, chat still handles it better than main
 
1 hour later…
02:04
@OlegValteriswithUkraine thank goodness
 
16 hours later…
18:24
Hello everyone. How this works?
<script>
class GenericClass {
	constructor() {
    	alert("hello");
    }
}

class Test {
	constructor(genericClass) {
    	new GenericClass();
    }
}

new Test(GenericClass);

</script>
@Dante Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
Sorry this is correct:
class GenericClass {
    constructor() {
        alert("hello");
    }
}

class Test {
    constructor(genericClass) {
        new genericClass();
    }
}

new Test(GenericClass);
18:41
wdym "how"?
Is it correct to pass a class as input parameter?
19:08
why would it not be correct?
It's a class not an object of that class.
20:04
@Dante You've always been able to pass around executable objects in JS. Classes are no exception. That's no different to how [1, 2, 3].forEach(fn) works - you still pass an executable object as an argument.
As for "is it correct" - maybe. Depends on what you're trying to do. It very well might be if you are trying to generalise construction in, say, a factory.
Although, in the example you have, there is no real need for this. Although, I assume it's just because it's an example.
OK. Thanks. I do not know much about JavaScript. I come from Java world.
Not much different from injection, in that case. Although with DI you pass a whole instance in the class, you don't have to instantiate it.
apologies for sounding harsh, but why not start with researching basics of the language when you are picking up a new one?
Although you can still do that in Java if you pass a Class object.
classes in ECMAScript have nothing to do with "classes" in languages like Java
20:10
I searched a lot and everywhere it is mentioned classes are functions. I don't get it.
Honestly, here Java is the one that's limited. Even C# is more flexible, since you can declare your class as generic and use the generic type. Java just type-erases it. And in C# you totally can have a class like this:
class Foo<T> {
	public Foo() {
		T myObj = new T();
	}
}
@Dante Functions are first-class citizens in JavaScript. That means you can assign them as values, pass them around, return them. Just like any other type. Java cheats to achieve something similar, since it compiles functions into classes with one method in them. At any rate, functions in JS are simple executable objects. A "class" is syntactic sugar around it. When you use GenericClass and pass it around, you're actually just passing a function. Specifically the constructor of the class.
So, any parameter can be called in JS. And in order to call it, you have few options. For simplicity, I'll focus on two - regular calls are just appending () at the end, so to call foo you use foo(). The second one is to use the new keyword: new foo() which will execute it as a constructor. Does a little bit of magic behind the scenes to give you an instance back from that call.
Class constructors are slightly special. They cannot be called without new. If you try GenericClass() you'd get an error. That's part of the sugariness - if it's a constructor, it doesn't really make sense to call it without new. Although, since class is syntactic sugar over regular functions, you could re-write the class without using the class syntax. And you'll be able to construct it without new.
But that's an aside, just in case you tried to omit the new and were confused why I "lied" to you and aid anything can be called. Anything could be called. Even a number or a string. If it's not a function, it just results in an error. And if it's a constructor, omitting new also throws an error.
You can, however, try calling other non-constructor functions with new. Most of the time, it would not really do anything special. But still executes them.

« first day (4600 days earlier)      last day (570 days later) »