Say I have a function like this
function myFunc(a, b, c)
{
if(a!=undefined) this.a = a;
if(b!=undefined) this.b = b;
if(c!=undefined) this.c = c;
}
And I want to set only the value for b, then I could do something like this.
myFunc(undefined, "some Value for b", undefined);
But I was wondering if there was a way in which I could do something like this for setting the value of b
myFunc(b:"some value for b");
This is probably wrong, but you probably see what I mean. I want to specify the name of the property along with the value so that I do not have to worry about passing undefined values. How would I do this?
Also feel free to change the title, I have no idea what this question should be called.
this.aetc? You're not instantiating an object, sothiswill be the global object.{}aroundb:"some value". The key concept is that you're passing an Object as an argument. Objects can be created using the object literal notation, which looks like this:{ propA: 'valueA', propB: 'valueB' }