DEV Community

Cover image for 7 interesting deprecated JavaScript features

7 interesting deprecated JavaScript features

Nikola Stojaković on August 04, 2021

Since it’s birth 26 years ago at Netscape, JavaScript has come a long way. A language which was used only to interact with Java applets and do simp...
Collapse
 
bugb profile image
bugb • Edited

Some example with with

with(Math){max(1,2)}
Enter fullscreen mode Exit fullscreen mode

To watch Object change, you can also Object.defineProperty

var o = {};
var bValue = 38;
Object.defineProperty(o, 'b', {,
  get() { console.log("Inside Get"); return bValue; },
  set(newValue) { console.log("Inside Set"); bValue = newValue; },
  enumerable: true,
  configurable: true
});
o.b=12
o.b
Enter fullscreen mode Exit fullscreen mode
Collapse
 
miketalbot profile image
Mike Talbot ⭐

Great list, I didn't have a clue about some of those :)

One other way of doing a "with like thing" having a go at the C# syntax I've seen is this:


function scope(value, fn) {
    return fn(value)
}

const cat = {
    details: {
        passport: {
            location: {
                city: "New York"
            }
        }
    }
}

scope(cat.details.passport.location, _ => {
    _.city = "Meowyork"
})
Enter fullscreen mode Exit fullscreen mode
Collapse
 
stojakovic99 profile image
Nikola Stojaković

That's nice!

Collapse
 
stojakovic99 profile image
Nikola Stojaković • Edited

Yup, that's another way of doing it - although that will return

Uncaught SyntaxError: redeclaration of non-configurable global property location
Enter fullscreen mode Exit fullscreen mode

in the browser since location is a global property - we can rename it to something else though.

Collapse
 
lionelrowe profile image
lionel-rowe • Edited

Don't forget let and const are already block scoped, so a simple alternative to your let block example is this:

let catName = 'Oswald'
let catAge = 2.5

{
    let catName = 'Luna', catAge = 2
    console.log(`${catName} (${catAge} years old)`) // Luna (2 years old)
}

console.log(`${catName} (${catAge} years old)`) // Oswald (2.5 years old)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
stojakovic99 profile image
Nikola Stojaković

You're right, thanks - I'll update the article now.

Collapse
 
krtirtho profile image
Kingkor Roy Tirtho

I've to say JavaScript changed so much that its hard to keep track of what have changes... But Proxy thing is just blew my mind. I never knew it was available. Thanks a lot

Collapse
 
michaelprimo profile image
Michael Primo

I only knew about with, which is used sometimes on code golfing 🙂 Nice article!

Collapse
 
hyggedev profile image
Chris Hansen

HTML wrapper methods on strings: "There are no alternatives for this monstrosity." Hahah 🤣 Wow, never knew they even exist tbh. Great stuff, thanks!

Collapse
 
ki1t3ty profile image
Ki1t3ty

great post thanks .

Collapse
 
tojacob profile image
Jacob Samuel G.

👍🏽

Collapse
 
shalvah profile image
Shalvah

Awesome article!

Collapse
 
triptych profile image
Andrew Wooldridge

Thanks! This was very informative.

Collapse
 
nombrekeff profile image
Keff

Nice post! Some of those are obscure, did not now a couple of them

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Glad you liked it!

Collapse
 
eidellev profile image
Lev Eidelman Nagar

Great post! I thought 'with' was a fever dream from my teenage years.

Collapse
 
stojakovic99 profile image
Nikola Stojaković

You're welcome!