Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
let  carLike = function(obj={},speed=1){
  obj.distance = 0;
  
  obj.move = function() {
    if (obj.fuel < 1) {
      throw new RangeError('Fuel tank is depleted')
    }
    obj.fuel--
    obj.distance += speed;
    
    return obj
  }
  
  obj.fullFuel = function () {
    obj.fuel = 3;
    return obj
  }
  
  return obj;
}
let tesla = carLike({name: "tesla"},10);
tesla.fullFuel();
tesla.move().move().move();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
dupontpro
0viewers