Skip to content

Instantly share code, notes, and snippets.

@juner
Created December 30, 2012 05:57
Show Gist options
  • Save juner/4411209 to your computer and use it in GitHub Desktop.
Save juner/4411209 to your computer and use it in GitHub Desktop.
よくやるテスト用メソッド[jQuery版]
jQueryを取得している際にコーディング時に設定するスクリプトでも。
test オプジェクトにテストの表示とクリアを設定します。
表示する際は下記の様にします。
test.print(text);
表示を消去する場合は下記の様にします。
test.clear();
body { background-color: #DDDDDD; font: 30px sans-serif; }
<div id="output">
</div>
//簡易表示用オブジェクト test;
//
//機能
//
// test.println(text);
// @param text 表示用のテキスト
// 予め設定しておいた要素に文字列を追加する。
//
// test.clear();
// 予め設定しておいた要素を空にする。
//
var test = function($,outputSelecter){
var output = null;
$(document).ready(function(){
output = $(outputSelecter);
});
return {
"print":function(_text){
if(output instanceof jQuery) $("<div/>").text(_text).appendTo(output);
},
"clear":function(){
if(output instanceof jQuery) output.text("");
}
};
}(jQuery,"#output");
//出力例
(function($){
var start =1;
var counter =start;
var end =10;
var key = setInterval(function(){
if(counter>end){
//クリア
test.clear();
counter =start;
}else{
//表示
test.print("test"+counter);
counter++;
}
},1000);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment