Well looking so your concept is correct, you should extend the "Date class" (since JS does not actually use classes for inheritance) and add its method, in the "format" case, but I believe that the error is being typed because JavaScript is poorly typed, so you do not need to define (it does not even accept type manipulation only conversions) and types it kind of understands by itself. p>
So by reformulating your code it looks something like this:
<script>
// Adiciona um método a classe "Date" e cria uma função anonima
Date.prototype.format = function(format) {
// Dias (g = Global ~ trocar todas ocorrencias)
var newFormat = format.replace(/\[d]/g, this.getDate()); // Troca o Dia
newFormat = newFormat.replace(/\[m]/g, (this.getMonth() + 1)); // Troca o Mês
newFormat = newFormat.replace(/\[Y]/g, this.getFullYear()); // Troca o ano Completo
newFormat = newFormat.replace(/\[y]/g, this.getFullYear().toString().substr(2, 4)); // Troca o ano Simples
// Horas (g = Global ~ trocar todas ocorrencias)
newFormat = newFormat.replace(/\[H]/g, this.getHours()); // Troca a Hora formato 24h
newFormat = newFormat.replace(/\[h]/g, (this.getHours() % 12 || 12)); // Troca a Hora formato 12h
newFormat = newFormat.replace(/\[i]/g, this.getMinutes()); // Troca os Minutos
newFormat = newFormat.replace(/\[s]/g, this.getSeconds()); // Troca os Segundos
// Retorna
return newFormat;
};
// Teste
var agora = new Date();
console.log(agora.format("[d]/[m]/[y] - [h]:[i]:[s]"));
console.log(agora.format("[d]/[m]/[Y] - [H]:[i]:[s]"));
console.log(agora.format("[d]/[m]/[Y] - [H]:[i]:[s] && [d]/[m]/[Y] - [H]:[i]:[s]"));
</script>
Testing in IE 11, Chorme 48+ and FireFox 43+.