Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过继承访问内置javascript对象功能_Javascript_Oop - Fatal编程技术网

通过继承访问内置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 .