通过继承访问内置javascript对象功能
事实上,我做错了。如何从继承的函数调用字符串长度属性?无法将参数传递给超级构造函数。另外,请参见此处-通过继承访问内置javascript对象功能,javascript,oop,Javascript,Oop,事实上,我做错了。如何从继承的函数调用字符串长度属性?无法将参数传递给超级构造函数。另外,请参见此处-。length不是原型属性。 // Function to inherit from paren(P) to child(C). function inherit(C, P) { var F = function(){}; F.prototype = P.prototype; C.prototype = new F(); C.uber = P.prototype
。length
不是原型属性。
// Function to inherit from paren(P) to child(C).
function inherit(C, P) {
var F = function(){};
F.prototype = P.prototype;
C.prototype = new F();
C.uber = P.prototype; // super
C.prototype.constructor = C; // reset
}
var child = function(arg) {}
inherit(child, String); //Inheriting from String
var oChild = new child("Get my Length");
console.log(oChild.length); // Gives 0 ????
var oString = new String('Get my Length');
console.log(oString.length); // Gives 13 .