This repository has been archived by the owner on Jun 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Extending Pudding Classes
Tim Coulter edited this page Sep 25, 2015
·
3 revisions
You can extend Pudding classes to add additional functionality. This is useful if you want to extend the functionality of a class without resorting to external methods:
// Persona is a contract class that has been created with Pudding.
Persona.extend({
addAvatar: function(image) {
// This method exists within a Persona contract class, so it already
// has a reference to its own address at this.address. This method
// can then be used to seamlessly add this persona’s avatar to IPFS
// without interacting with functions external to the Persona object.
// ... implementation ...
}
});
// After calling .extend(), new instances of the Persona class will
// have the .addAvatar() function available.
var persona = Persona.at(“0x12345abcde...”);
persona.addAvatar(someImage); // calls out to ipfs, saves hash on the blockchain
Note: Extended functions are not automatically promisified, so you'll have to promisify those functions yourself (or have those functions return a Promise) in order to use those functions within a promise chain.