Comments (4)
Sure there is a way. Actually, three ways. :)
If your POJO props need to go the __proto__
then:
const obj = {name: 'something'}
const Thing = stampit.methods(obj).compose(OtherStamp, etc..)
If they need to be regular properties (a-la mixin) then:
const obj = {name: 'something'}
const Thing = stampit.props(obj).compose(OtherStamp, etc..)
If you want some control over assignment logic then:
const obj = {name: 'something'}
const Thing = stampit.init(function () {
this.name = obj.name;
}).compose(OtherStamp, etc..)
A good idea would be to extract that stamp to a separate variable, which would have a descriptive name. For example:
const HaveNameSomething = stampit.props({name: 'something'})
const Thing = stampit(HaveNameSomething, OtherStamp, etc..)
Here is a 5 min article which can help you to get your head around the above code.
from stampit.
Amazing, so simple.. thank you.
from stampit.
Quick followup, if obj
was instantiated from a Stamp, its methods are on proto, which means neither .props nor .methods will pick them up:
const Bar = stampit.methods({
bar() {
console.log('bar');
}
});
const obj = Bar();
const a = stampit.props(obj)(); // a.bar() undefined
const b = stampit.methods(obj)(); // b.bar() undefined
const c = stampit.methods(obj.__proto__)(); // bcbar() exists
Is this recommended if you want to enhance an existing Instance:
const d = stampit.props(obj).methods(obj.__proto__).compose(Something)()
from stampit.
We recommend developers to do whatever they want with they code!
Stampit do not have any formal rules you should follow.
So, yeah. Your code is absolutely valid and recommended. :)
Good job on reading the above mentioned article. π
from stampit.
Related Issues (20)
- Performance degradation in node.js 8 HOT 12
- 'Use metadata in static functions' sample code throws an error HOT 1
- Suggestions on how to leverage stampit w/ Vue.js? HOT 6
- Need some guidance HOT 5
- β¨ Add .version to stampit object HOT 4
- Link to API docs is broken in Readme? HOT 3
- [Bug] RangeError: 'Maximum call stack size exceeded' when use setters HOT 3
- [SOLVED] How to express stampit factories and instances in typescript HOT 4
- Implementing the Decorator Pattern HOT 5
- π Stamps vs Traits vs Mixins vs Has-a/Is-a composition vs Multiple inheritance (classes) feature-by-feature comparison HOT 3
- when i return something in init(), and then i can not call all methods HOT 10
- when i use getter and setter, i got this, is this a issue? HOT 21
- array in props persist across instances of stamp HOT 1
- Website is down HOT 3
- Provide ES6 Module build HOT 8
- Not so much an issue but a question. HOT 4
- Please helpοΌI would like update V2 to V4 HOT 1
- RFC: TypeScript version bump + Type enhancements HOT 4
- Can't seem to mock axios in a stamp HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stampit.