Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Wrapper() {}
- Wrapper.prototype.getTheDude = function (callback) {
- callback({
- id : 1
- });
- };
- Wrapper.prototype.getAwesomeList = function (callback) {
- var arrayOfObjs = [];
- arrayOfObjs.push({id: 1});
- arrayOfObjs.push({id: 2});
- arrayOfObjs.push({id : 3});
- arrayOfObjs.push({id : 4});
- callback(arrayOfObjs);
- };
- function DudeObject() {
- this.dude = {};
- this.awesomeList = [];
- }
- DudeObject.prototype.setTheDude = function (wrap) {
- var self = this;
- wrap.getTheDude(function (data) {
- self.dude = data;
- });
- };
- DudeObject.prototype.setAwesomeList = function (wrap) {
- var self = this;
- wrap.getAwesomeList(function (data) {
- for (var i = 0; i < data.length; i++) {
- self.awesomeList.push(data[i]);
- }
- });
- };
- DudeObject.prototype.toString = function () {
- var string = 'The Dude:\n' +
- '\tid:' + this.dude.id + '\n';
- for (var i=0;i<this.awesomeList.length;i++) {
- string = string + 'Awesome List:\n' +
- '\tid:' + this.awesomeList[i].id + '\n';
- }
- return string;
- };
- var wrap = new Wrapper();
- var dudeObj = new DudeObject();
- dudeObj.setTheDude(wrap);
- dudeObj.setAwesomeList(wrap);
- console.log(dudeObj.toString());
Add Comment
Please, Sign In to add comment