Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ``` javascript
- var Vehicle = function() {
- };
- Vehicle.prototype.setName = function(name){
- this.name = name;
- return this;
- }
- Vehicle.prototype.setColor = function(color){
- this.color = color;
- return this;
- }
- Vehicle.prototype.setType = function(type){
- this.type = type;
- return this;
- }
- Vehicle.prototype.save = function(){
- console.log('saving ' + this.name + ' to the database')
- return this;
- }
- //WITHOUT CHAINING
- var car = new Vehicle();
- car.setName('Freddy')
- car.setColor('black')
- car.setType('Volvo')
- car.save();
- //WITH CHAINING
- var car = new Vehicle().setName('Freddy').setColor('black').setType('Volvo').save();
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement