Skip to content

Instantly share code, notes, and snippets.

@sdellis
Created September 14, 2017 16:29
Show Gist options
  • Save sdellis/201cbffd512dd61026a70ae768c91e2d to your computer and use it in GitHub Desktop.
Save sdellis/201cbffd512dd61026a70ae768c91e2d to your computer and use it in GitHub Desktop.
Bind demo // source https://jsbin.com/remutu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bind demo</title>
<script src="https://cdn.rawgit.com/remy/bind/928c52ce335d6fd2c824b536a97efa460554b9e0/dist/bind.min.js"></script>
<style id="jsbin-css">
*, input {
font-family: sans-serif;
font-size: 16px;
padding: 2px;
}
</style>
</head>
<body>
<p>Score: <span class="score">0</span></p>
<p>Username: <input name="username"></p>
<script id="jsbin-javascript">
var user = Bind({
name: '[new user]',
game: { score: 0 }
}, {
'game.score': 'span.score',
name: 'input[name="username"]'
})
// in the game
user.game.score += 25;
setInterval(function () {
console.clear()
console.log(user.name)
}, 500);
</script>
<script id="jsbin-source-css" type="text/css">*, input {
font-family: sans-serif;
font-size: 16px;
padding: 2px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var user = Bind({
name: '[new user]',
game: { score: 0 }
}, {
'game.score': 'span.score',
name: 'input[name="username"]'
})
// in the game
user.game.score += 25;
setInterval(function () {
console.clear()
console.log(user.name)
}, 500);</script></body>
</html>
*, input {
font-family: sans-serif;
font-size: 16px;
padding: 2px;
}
var user = Bind({
name: '[new user]',
game: { score: 0 }
}, {
'game.score': 'span.score',
name: 'input[name="username"]'
})
// in the game
user.game.score += 25;
setInterval(function () {
console.clear()
console.log(user.name)
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment