HenrikJoreteg / HenrikJoreteg/extend-object

Problem when two children implement the same method

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5
Forks
1
PR merge metrics
No merged PRs in 30d

Description

The best way to describe it is with a test:
test('two extenders', function (t) {
var start = {};
var hipster = extend(start, {
greet: function() {
return 'Heyo';
}
});
t.equal(hipster.greet(), 'Heyo');

```
var spanish = extend(start, {
greet: function() {
return 'Hola';
}
});
t.equal(spanish.greet(), 'Hola');

//this next line fails, because hipster.greet() now returns 'Hola', but I think most devs would want it to return "Heyo"
t.equal(hipster.greet(), 'Heyo');
t.end();
```

});

I think it's because the two children share the same prototype, and so the second one's function declaration just overwrites the first.
I don't have a PR to offer - still thinking about how this could be addressed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the extend function and reproduce the supplied "two extenders" test with two children sharing the same start object. Trace how each child receives greet and determine how prototype sharing causes the second definition to affect the first. Done means hipster.greet() remains "Heyo" while spanish.greet() returns "Hola".

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.