There is a method in PHP called extract which does exactly what I want to do here. Say I have an object that looks like this:
var data = {
name: "Olly"
age: 19
};
I want to run a method like extract(data) so that I can then access the properties in that object by just using name and age, instead of data.name and data.age.
I've done a bit of Googling and couldn't find anything.
withstatement is more closely similar to PHP'sextractmethod. That being said,withis not very common and I would not use it unless you truly understand how it works. See developer.mozilla.org/en/JavaScript/Reference/Statements/with