1

getTime オブジェクトのプロトタイプを使用して、Date オブジェクトのすべてのプロパティ/メソッドを継承/取得しようとしていますが、何か不足しています。正しい方向に向けてください。

//empty constructor 
function getTime(){}

//attempt to inherit all of the properties and methods of Date object
getTime.prototype = new Date();

//create a new Date object and test
//this works
var wt = new Date();
alert(wt);

//create a new getTime object and test.
//I was uner the impression that getTime object 
//now has access to all the properties/methods of the Date object.
//'This generates:TypeError this is not a Date object.'
var wt2 = new getTime();
alert(wt2.getHours());

JSfiddle: http://jsfiddle.net/nysteve/QHumL/12/

4

2 に答える 2