Comments (10)
Thanks for the question!
Here is a quote from our docs
If you return anything from an initializer then it becomes the object instance.
Feel free to ask any other questions. π
Cheers
from stampit.
and then, how can i get a stamp when i return an object in init method.
from stampit.
describe what is my target: i want a new object that has two feature:
- IT copy all property from another object, that object from json, so it is different every time.
- It is a stamp, example a mckpoint.
and how can i get the target? thank you.
from stampit.
Hello @lornally
Looks like you need to understand the basics of stamps. I'd highly recommend going through this little article: https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0
It's very easy to solve your problem. :)
Do not create new objects inside the init
. Think of init
as a class constructor. Use this
.
.init(function({ lng, lat, info, ...p }) {
t.p = p;
t.lng = lng;
})
Does that answer?
from stampit.
actually, i write code like this:
const mckpath = stampit()
.init(function init({ start, end, list, ...p }) {
this.start = mpoint(start);
this.end = mpoint(end);
this.train = train({ list });
Object.keys(p).forEach(e => { //here i got all last property, but can we elegant more
this[e] = p[e];
});
})
i use object.key got all property, but can we do it more elegant?
and i will read tho topic, thank you:)
and your code should use function not =>, because use 'this'
from stampit.
Thanks for the correction about =>
. Indeed there should be function
. Corrected now.
Instead of the forEach
you should use Object.assign(this, p);
from stampit.
thank you very much, and can we do it more elegant than object.assign?
from stampit.
Yep. Here is my favourite method
https://www.npmjs.com/package/@stamp/arg-over-prop
from stampit.
thank you, you are really nice:) i will learn your suggest:)
and i have see arg-over-prop, that is a good solution.
from stampit.
Thank you for the kind words mate!
Feel free to contact any time.
Cheers
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
- Compose using an instance? HOT 4
- [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 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.