Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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
Jquery 你能继承局部变量吗?_Jquery_Private_Extend_Inheritance - Fatal编程技术网

Jquery 你能继承局部变量吗?

Jquery 你能继承局部变量吗?,jquery,private,extend,inheritance,Jquery,Private,Extend,Inheritance,我想知道是否执行了下面的代码,它是否从NewDragDrop函数继承了局部变量?NewDragDrop()是否是另一个类的构造函数有关系吗 function NewDragDrop (imageReference, imageTitle){ var image; var title; } function InheritDragObject (imageReference, title){ $.extend(true, this, new NewDr

我想知道是否执行了下面的代码,它是否从NewDragDrop函数继承了局部变量?NewDragDrop()是否是另一个类的构造函数有关系吗

function NewDragDrop (imageReference, imageTitle){
       var image;
       var title;
}

function InheritDragObject (imageReference, title){

       $.extend(true, this, new NewDragDrop(imageReference, title));
}

不是我的反对票,但你可以很容易地尝试一下。只需执行这段代码,然后执行类似于
vard=newinheritDragObject(“ref”,“title”)
的操作并检查结果。然后,如果您不理解结果,请发布一个问题,请某人解释。当您这样使用
$.extend
时,所有
NewDragDrop
原型方法都会作为自己的属性复制到
InheritageDragObject
实例中,这首先会破坏原型(作为方法容器)的用途。可以使用伪经典继承(与函数一起使用),也可以将原型继承与
对象一起使用。创建
$.extend
方法未针对继承进行调整-它用于其他目的。