Skip to content

Instantly share code, notes, and snippets.

@MikeDigitize
Last active May 10, 2017 07:40
Show Gist options
  • Save MikeDigitize/5d9101c2882324da902a8983384facc5 to your computer and use it in GitHub Desktop.
Save MikeDigitize/5d9101c2882324da902a8983384facc5 to your computer and use it in GitHub Desktop.
/* Modify the below to create a new builder constructor pattern
Give Video a static property called `make` - an object - that creates the following API:
Video.make
.setSrc('/videos/video.mpeg')
.setTitle('AO Video')
.setLoop(true);
which returns a new instance of Video
*/
function Video(){}
Video.prototype.setSrc = function(src) {
this.src = src;
};
Video.prototype.setTitle = function(title) {
this.title = title;
};
Video.prototype.setLoop = function(loop) {
this.loop = loop;
};
var vid = new Video();
vid.setSrc('/videos/video.mpeg')
vid.setTitle('AO video')
vid.setLoop(true);
console.log(vid); // {src: "/videos/video.mpeg", title: "AO video", loop: true}
//////
function Video() {}
Video.prototype.setSrc = function(src) {
this.src = src;
return this;
};
Video.prototype.setLoop = function(loop) {
this.loop = loop;
return this;
};
Video.prototype.setTitle = function(title) {
this.title = title;
return this;
};
Video.make = (function() {
return new Video();
})();
var vid = Video.make
.setSrc('/videos/video.mpeg')
.setLoop(true)
.setTitle('AO Video');
console.log(vid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment