Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created August 16, 2011 14:51
Show Gist options
  • Select an option

  • Save xulapp/1149281 to your computer and use it in GitHub Desktop.

Select an option

Save xulapp/1149281 to your computer and use it in GitHub Desktop.
残酷な getter
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
var akarin = {name: 'あかり'};
var yryr = Object.create(null, {
standby: {value: standby},
start: {get: getStart},
});
function standby(c) {
c.serifu = 'はっじまーるよー!';
return c;
}
function start(c) {
alert(c.name + '「' + c.serifu + '」');
}
function getStart() {
akarin.serifu = '';
return start;
}
function test1() {
yryr.start(yryr.standby(akarin));
}
function test2() {
yryr.standby(akarin)
yryr.start(akarin);
}
</script>
</head>
<body>
<button onclick="test1()">あかりん 1</button>
<button onclick="test2()">あかりん 2</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment