Skip to content

Instantly share code, notes, and snippets.

@otiai10
Created August 20, 2013 04:02
Show Gist options
  • Save otiai10/6276992 to your computer and use it in GitHub Desktop.
Save otiai10/6276992 to your computer and use it in GitHub Desktop.
JSっぽいコードってこんなん?
function myNum(num) {
this.value = num;
}
myNum.prototype.toString = function(){
return String(this.value);
}
myNum.prototype.increment = function(){
this.value++;
return this;
}
myNum.prototype.to0PadStr = function(digit){
var pad = '';
for(var i=0;i<digit;i++){
pad += '0';
}
return String(pad + this.value).slice(-digit);
}
var i = new myNum(3);
console.log('Raw:', i.toString());
console.log('Inc:', i.increment().toString());
console.log('Pad:', i.increment().to0PadStr(10));
/*
% node zeroPadding.js
Raw: 3
Inc: 4
Pad: 0000000005
*/
@otiai10
Copy link
Author

otiai10 commented Aug 20, 2013

TypeScriptで書きたさある

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment