Skip to content

CodingShower

  • Home
  • About
Skip to content

CodingShower

All Things Software

Tag: javascript

JavaScript Add a Custom Function or Property to All Objects/Variables

Posted on December 30, 2022December 31, 2022 by Rick

Everything in JavaScript is an object. When you try to access a property on the object, it is looked up on the object but if not found, then looked up on the object’s prototype. The prototype is another object accessible via ob.__proto__ or even better Object.getPrototypeOf(ob). This prototype is also an object which further has […]

0

JavaScript Array.prototype.sort() vs Array.prototype.toSorted()

Posted on December 16, 2022December 16, 2022 by Rick

The sort() array method sorts its elements in place (no copy is made) and returns a reference to the same array. Hence the array is mutated. The default sort order of this function is ascending but we can pass a compare function to define our own behaviour (like sorting in descending order). Here’s another example […]

0

JavaScript Array.prototype.reverse() vs Array.prototype.toReversed()

Posted on December 16, 2022December 16, 2022 by Rick

The reverse() array method reverses its elements in place (no copy is made) and returns a reference to the same array. Hence, it mutates the array. The TC39 Change Array by copy proposal introduced a new method Array.prototype.toReversed() that does the same thing as reverse() but returns a new copy with the changes instead of […]

0

JavaScript Parse and Convert Raw HTML String to DOM Nodes

Posted on April 3, 2022April 3, 2022 by Rick

Let’s say we have an HTML string like the following that we just want to convert into pure DOM nodes: What are our options ? Let’s quickly go through all of them. Range API The Range API provides us with a method called createContextualFragment that we can use to generate a DocumentFragment containing the parsed […]

0

JavaScript Inject/Add or Append Raw Plain HTML Strings into DOM Nodes

Posted on April 3, 2022April 3, 2022 by Rick

So you want to either inject (add) or append raw HTML strings into the DOM directly or convert the HTML string into DOM nodes and then flush them ? Let’s see all the different ways to do them. We’ll assume that the following HTML string needs to be parsed and and added to the following […]

0