I'm adding typed objects to JS in HotTea (along with the promised "real classes").
This is how they look so far:
je = TypedObject({
"name": String,
"age": Number
});
je.name // null
je.age // null
je.name = null; // That's fine.
je.name = new Object(); // TypeError: Type Object does not match required type String.
je.name = "John"; // TypeError: Type String does not match required type String.
// Gonna fix the message to account for primitive type names.
je.name = new String("John Egbert");
je.age = new Number(13);
je.name; // John Egbert
There also is a way to use primitive types as their Object
equivalents (using the strict
parameter):
ds = TypedObject({
"creator": Object,
"name": String
}, false);
ds.creator = "test"; // Throws an error (because I still need to implement the proper behavior).
ds.creator = new String("Andrew Hussie");
ds.name = "Dave Strider";
I also do wanna be able to add a way to add new properties later on, but that's gonna be hard due to the current architecture. But, I hope you all are excited for HotTea!
Thanks for reading!
Cheers!
Cheers!
Top comments (11)
Looking forward for the full release of the library :D
Thanks. Can't wait to release the first version (a0.01) containing
TypedObjects
and a few comparison utils.Quick question: will there be a github repo for it (or is there already one)
There's an OLD version on GH, if you'd like to see. But yes, (new) HotTea will get its own repo.
Ok. Have fun working on it!
Want to see the old version?
Sure
@baenencalin this: github.com/CalinZBaenen/HotTeaJS?
Yes.
Sorry it took me a minute to find, and a minute to respond. I was on mobile, and getting on PC.
What do you think of the old version?
That's ok :D. I gotta go now, good luck with that library