我正在尝试通过使用我的 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/