While working with prisma nexus and examining the prismaObjectType
, I came across something unusual.
A simple example of this is as follows:
In a basic function, demo(p)
, the parameter p
should be an object.
function demo(p) {
console.log(p);
console.log(p.normal);
console.log(p.normal());
}
I am passing a key normal
with a function as its value.
demo({a:"a", normal: function(){console.log("normal")}, b:"b"});
The output in the console is:
{a: "a", normal: ƒ, b: "b"}
ƒ (){console.log("normal")}
"normal"
What's intriguing is that I'm passing a method without using the keyword function, also without specifying a key for it.
demo({a:"a", weird(){ console.log("it is weird") }, b:"b"});
// console
{a: "a", weird: ƒ, b: "b"}
ƒ weird(){console.log("it is weird")}
it is weird
{a:"a", the unusual part >>>>> weird(){console.log("it is weird")} <<<, b:"b"}
What do you call this type of practice? Any thoughts or comments?