Anyone here extremely experience with Javascript?
If so, I got a question for you that Ive had since I started learning the language.
You know how to create an object using a constructor is
var object = new Object();
?
I was wondering if its possible to add arguments into the parenthesis of the object constructor. Thanks!
that just creates an "Object" object
Object is the class from which more specialized types inherit. I think pretty much all languages with object-oriented features have something like this. for example, Python's
object or Java's
java.lang.Object. and usually in these cases you don't have to explicitly say that the class inherits from that class, it's just assumed
these root classes define some methods and maybe properties that
all classes should have, but there's not often a reason to use them yourself. you might never have any reason to type what you have in that code block there
and to answer your actual question, it can take arguments
> var o = new Object();
> o
Object {}
> var o = new Object(12);
> o
Number {[[PrimitiveValue]]: 12}
> var o = new Object(true);
> o
Boolean {[[PrimitiveValue]]: true}but under normal circumstances you'd be better off just using primitives