- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The function is also incorrectly named, because, in essence, it merges the "new" object into the "old" object. (It fails to clear the old object before adding the values from the new object to it.)
Admin
If you're going to re-invent the wheel, shouldn't you make one that's substantially better, not substantially worse?
I mean, judging by this website, people tend to do the latter, but still...
Admin
To be fair, non functional style methos that mutate their single argument often return the instance. By returning the instance rather than void, the caller can chain method calls. It isn't fair to assume they meant to mimic functional programming.
Admin
Like the built-in
Array.sort.Admin
and then you have SHAI-HULUD2 when you are using stock solutions
Admin
Our submitter wonders, "Is there a way to train an AI to not let people type this?" I would't think that will help - too much AI just copying published code or other "knowledge" without knowing whether the code is good, once-good but overtaken by subsequent developments, or just plain wrong. For any given relatively common topic, there will be hundreds sites repeating the same incorrect advice because the goal was advertising revenue at minimum cost, not well-curated content.
TLDR: GIGO.
Admin
I don't see this has even remotely trying to be functional, just using the pattern of returning the object for chaining.
I am however irritated by the nonsensical name of the parameters -- old versus new, and it copies new into old? That makes no sense. "Src" vs "dst" would be so much more logical.
Admin
Further despite the name
objectReplaceit's not a clone operation; it's a merge operation. It amounts toold = old + newwhere any properties inoldcommon to both are replaced bynew's values, and the final property list ofoldis the union of both.Naming is hard. It's that much harder when your native language isn't the language of the names.
Just illiterate garbage end to end.
Admin
Admin
code that need to clone an object is the real WTF, isnt it?