jQuery and Vanilla JS Are Friends: The Interop Escape Hatches
You don't migrate a decade of jQuery in one heroic rewrite - you make the two worlds interoperate. Element extraction, wrapping, iteration and event bridging, mapped precisely.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
You don't migrate a decade of jQuery in one heroic rewrite - you make the two worlds interoperate. Element extraction, wrapping, iteration and event bridging, mapped precisely.
jQuery keeps a stack of every traversal you make. .end() pops it, .addBack() merges it - and suddenly one chain does what used to take three variables.
Callback pyramids after fadeOut, logic that runs mid-animation, the queue backlog from impatient clicking - all solved by three methods most jQuery users never met.
.off("click") nukes every click handler including ones you don't own. Namespaces let you unbind exactly your handlers - one suffix, surgical cleanup.
Warnings scroll past in logs while your app continues in a corrupted state. One error handler converts them to catchable ErrorExceptions - and changes how you write file and network code.
When each match needs logic - lookups, formatting, escaping - preg_replace hits its ceiling. The callback variant runs code per match, and preg_quote keeps user input from breaking your patterns.
Mass-assignment bugs happen when request data flows unfiltered into updates. Two array functions - intersect_key and diff_key - are the terse, auditable filter.
"item10" before "item2", "Öl" after "z", uppercase clustering before lowercase - default sorts betray human expectations three different ways. PHP has a fix for each.
Keyed destructuring, foreach unpacking, swaps, nested extraction - the [$a, $b] syntax has quietly become one of PHP's best readability tools.
Every date in a month, every Monday for a year, billing cycles between two dates - DatePeriod iterates ranges natively, immutably and off-by-one-free.
Currency placement, month names, ordinal suffixes, "1.234,56" vs "1,234.56" - the intl extension knows every locale's rules, and most PHP developers never call it.
The 40-line value object - properties, constructor assignments, getters - collapses into a declaration. Modern PHP makes immutable data carriers nearly free to write.