RPG Maker Forums

cabfe
cabfe
So you've found the rightly wrong answers, right?
Poryg
Poryg
Only one of them I was sure they had wrong.
Jonforum
Jonforum
what was answers and the question
Poryg
Poryg
foo = {
bar : 10;
}
p = Object.create(foo);
delete p.bar;
console.log (p.bar);
The correct answer should be undefined, but they said it was 10.
Jonforum
Jonforum
ho ok nothing, its stupid and strange !
Poryg
Poryg
Agreed. That's why I didn't take the test seriously.
Llareian
Llareian
Are you missing a part where foo was defined earlier? I'm having trouble making sense of it as it is. It's not a function and it's not an object...
Poryg
Poryg
If foo is not an object, what else would it be?
It is an object, the fact that it is {} says it is an object. [] is used for arrays and associative arrays, {} for objects.
It is an Object with property bar. p is an object generated from foo. And from p the property bar gets deleted, so it should be undefined, not 10.
Llareian
Llareian
Yeah but that's not how you instantiate object properties. You use :, not =;. Throw it into console. It doesn't work.
Poryg
Poryg
That is because I rewrote the code quickly, not copypasted it :D But thank you for pointing it out :}
Llareian
Llareian
It's like a weird amalgam of an object initializer and a constructor function.
Poryg
Poryg
Yup, I may have forgotten Object.create (foo.prototype) too. However, properties written like that are a feature of ES6.
Llareian
Llareian
I'd have gone with p = new Object(foo), but either way, whether p wasn't created from foo correctly or it was and you deleted p.bar, you're right, it should still be undefined.
Hudell
Hudell
Want an explanation on the 10?
Poryg
Poryg
I guess I definitely need it even if I don't want it :D
Hudell
Hudell
Try this:

var obj = { value : 15 };
var p = Object.create(obj);

obj.value = 20;
delete obj.value;
console.log(obj.value);
Hudell
Hudell
delete obj.value turns the value property back to 15 instead of undefined. I guess delete works more like a "revert to default" than actually deleting.
Poryg
Poryg
How comes deleting value from obj deletes value from p as well, but deleting value from p doesn't delete value from p?
Poryg
Poryg
Ah, I see.
Hudell
Hudell
I would have got that answer wrong too.

Latest Threads

Latest Posts

Latest Profile Posts

So ... uh ... this weekend I have to cut my husband's hair. He searched long and hard - highest mountains, deepest valleys, across vast oceans. All hairdressers are now closed. So it's me.
Yanfly Save Event Locations plugin is a real time saver.
Keep events still for once!
Yesterday.... 6 total subscribers on my YouTube, today 33. To think I was foolishly trying to put out videos to grow my subscriber base. That's just crazy talk. :LZSskeptic:

I wonder if I can hit 100 by the end of the week. :LZSexcite:
how to make small eyes so cute like that... ah... I give up...
Sometimes I wonder if we're ever going to be able to call Blizzard by its name, or if it's fully fledged Activision forever.

Forum statistics

Threads
95,756
Messages
931,656
Members
126,158
Latest member
GabrelleGail
Top