Skip to content

Instantly share code, notes, and snippets.

@heavenshell
Last active December 14, 2015 11:28
Show Gist options
  • Save heavenshell/5079622 to your computer and use it in GitHub Desktop.
Save heavenshell/5079622 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Sample</title>
<script type="text/javascript">
window.onload = function () {
function Foo() {
}
Foo.prototype = {
dict: {},
data: null,
list: [],
setData: function (data) {
this.data = data;
},
addItem: function (data) {
this.list.push(data);
},
addDict: function (key, value) {
this.dict[key] = value;
}
};
var foo = new Foo();
foo.addDict('key', 'value');
foo.setData('hello');
foo.addItem('world');
var foo2 = new Foo();
console.log(foo2.data); // null
console.log(foo2.dict); // {} を想定したけど実際は {key: 'value'}
console.log(foo2.list); // [] を想定したけど実際は ['world']
};
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment