Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Follow up comment on my blog post "Refactoring Workflows to Chain of Actions"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
Created using /
Source can be edited via /anakul/8/edit
-->
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<title>Sandbox</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
body { background-color: #000; font: 16px Helvetica, Arial; color: #fff; }
</style>
</head>
<body>
<button >Change Div</button>
<div>shalom</div>
<p>Hello from JS Bin</p>
<p id="hello"></p>
<script>
var House = {
leave : function(dude) {
return dude.name + ' leaves the house';
},
closeTheDoor : function(dude) {
return dude.name + ' closes the door';
}
};
var Car = {
use : function(dude) {
return dude.name + ' jumps in the car';
},
travelToThePark : function(dude) {
return dude.name + ' drives to the park';
} ,
park: function(dude) {
return dude.name + ' parks the car';
}
};
var Bicycle = {
use : function(dude) {
return dude.name + ' jumps in the bike';
},
travelToThePark : function(dude) {
return dude.name + ' drives to the park';
} ,
park: function(dude) {
return dude.name + ' parks the bike';
}
};
var Park = {
enter : function(dude) {
return dude.name + ' enters the park';
}
};
var GoesToThePark = {
toEnjoyWeather : function(dude) {
var messages = [],
vehicle = dude.hasCar ? Car
: Bicycle;
messages.push(House.leave(dude));
messages.push(House.closeTheDoor(dude));
messages.push(vehicle.use(dude));
messages.push(vehicle.travelToThePark(dude));
messages.push(vehicle.park(dude));
return messages;
}
};
var dude = { name : 'It' ,hasCar : true };
var result = GoesToThePark.toEnjoyWeather(dude);
console.log(dude);
console.log(result);
</script></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment