Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created January 9, 2013 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/4490318 to your computer and use it in GitHub Desktop.
Save shoyan/4490318 to your computer and use it in GitHub Desktop.
カスタムオブジェクトのサンプル
<script>
var Obj = function(){
var background = "#fff";
var state = "on";
this.change_state = function(){
if(state === "on"){
state = "off";
background = "#000";
} else {
state = "on";
background = "#fff";
}
}
this.get_color = function(){
return background;
}
this.get_state = function(){
return state;
}
}
var obj = new Obj();
function clicked(){
obj.change_state();
$('#d1').attr('style', "background-color:" + obj.get_color());
$('#d0').text("状態:" + obj.get_state() + " 背景色: " + obj.get_color());
}
</script>
<input type="button" value="背景色を変更" onclick="clicked()" />
<br />
<div id="d0" style="background-color:white !important;">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment