stampit-org / stampit

OOP is better with stamps: Composable object factories.
https://stampit.js.org
MIT License
3.02k stars 102 forks source link

Accidentally overriding instance methods when passing `properties` #184

Closed dwiyatci closed 8 years ago

dwiyatci commented 8 years ago

Hello,

this morning I accidentally override (or rather, hide?) one of my instance methods when passing properties to the factory function. It goes something like:

var Person = stampit({
    methods: {
        greet: function() {
            console.log('hello, world');
        }
    }
});

var foe = Person({
    greet: function() {
        console.log('goodbye, world');
    }
});
foe.greet(); // goodbye, world

var friend = Person();
friend.greet(); // hello, world

I know the greet method in the prototype will be safe, but just wondering if there is any way to prevent this kinda thing from happening?

ericelliott commented 8 years ago

Why would you want to prevent this from happening? This is expected behavior. This is the canonical way to override delegate prototype methods...

dwiyatci commented 8 years ago

I guess you're right. This behaviour should be expected. I think I got mixed up a bit between concatenative and delegative prototyping. Thanks for the justification.