I wake up at 4am, and write custom JSON objects that I thought of while meditating and use them to automatically send out thousands of connection invites telling every person I found their profile so unique and would love to connect and invite them to my local jack off club where only non gay men are allowed in.
class JsonObject {
#result; // Resulting object
/**
* Create an empty json object
*/
constructor() {
this.#result = {};
}
/**
* Get the current json object
* @returns the current jason object
*/
get() {
return this.#result;
}
/**
* Returns the string representation of the
json object
* @returns the strinified object
*/
toString() {
return JSON.stringify(this.#result);
}
/**
* Check if we have a property
* @param {String} name
is the name of the property
* @returns
true if the property is not undefined, else fal
se
*/
hasProperty(name) {
return (this.#result[name] !== undefined
);
}
/**
* Create a new property
* @param {String} name
is the name of the new property
* @param {Any} value
is the value of this property
*/
add(name, value) {
this.#result[name] = value;
}
}
OK I'll risk looking stupid here. This is obviously more overhead than a raw Object, and it's probably bad code ... but it's not necessarily bad code.
Two places where I might let this past a code review:
This is public API and we're intentionally limiting the API scope to keep options open for our future implementation. e.g. maybe our future internals won't be a clean fit with the full Object.*() and Object.prototype.*() API.
This is interim code in a refactor branch. This class might be OK in the early steps of an Object-to-something-else refactor where we're removing all the Object.*() and Object.prototype.*() calls without breaking everything.
The inarguably bad part of this code is that there's not a comment explaining why this class exists.
In JS you'd never call "new Object" directly. You're always going to just use it with {} to create a generic object or you'd have a more meaningful model class representing something (to which you can then define a toJSON method to customize what data is returned when serialized).
We may be talking about different things? I agree {} the right way to make a new object, but sure you'll call Object directly, e.g. Object.keys(foo) or Object.hasOwn(foo, bar)
182
u/[deleted] Apr 19 '23
Average LinkedIn dev-fluencer post be like
69
u/gipp Apr 19 '23
the current jason object
38
u/thanatica Apr 19 '23
Why use a Map when you can write a bad one yourself, ey?
33
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 19 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
19
u/lucpilgrim Apr 19 '23
Thinking quickly, Dave constructs a homemade JSON object, using only some string, a squirrel, and a JS object.
25
u/____-__________-____ Apr 19 '23
OK I'll risk looking stupid here. This is obviously more overhead than a raw Object, and it's probably bad code ... but it's not necessarily bad code.
Two places where I might let this past a code review:
Object.*()andObject.prototype.*()API.Object-to-something-else refactor where we're removing all theObject.*()andObject.prototype.*()calls without breaking everything.The inarguably bad part of this code is that there's not a comment explaining why this class exists.
8
u/new2bay Apr 19 '23
Oooooooook.
19
u/matt1484 if true else false Apr 19 '23
That JSON needs to be J-gone
6
u/pearcidar43 Apr 19 '23
that font's nice, what is it?
5
u/HealthyMacaroon7168 Apr 19 '23
Jason
9
u/secret_hidentity Apr 19 '23
‘’’ The comme Nts nicely document This jason object. ‘’’
2
u/NMO Apr 19 '23
Is that the one where JSON goes to space?
2
u/IBJON Apr 19 '23
It looks like they were trying to create a singleton, but botched the execution.
1
u/LastStar007 Apr 19 '23
What is that symbol in hasProperty? Is that legal JS?
1
u/grasspopper Apr 19 '23
Who uses #variables ? Is that the new _ ?
1
u/[deleted] May 20 '23
The jason objects do be objecting
0
u/[deleted] Apr 19 '23
[deleted] — view deleted comment