Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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 如何读取jQuery之外的类属性?_Javascript_Jquery_Oop - Fatal编程技术网

Javascript 如何读取jQuery之外的类属性?

Javascript 如何读取jQuery之外的类属性?,javascript,jquery,oop,Javascript,Jquery,Oop,我已经编写了一个JS类,我想使用jQuery的API,但不知道如何读取jQuery对象之外的值 function Slideshow( originalslideshowid, nextslideshowId ) { this.originalslideshowId = originalslideshowid; this.nextslideshowId = nextslideshowId; $("#nextslideshow").click( function(e)

我已经编写了一个JS类,我想使用jQuery的API,但不知道如何读取jQuery对象之外的值

function Slideshow( originalslideshowid, nextslideshowId ) {

    this.originalslideshowId = originalslideshowid;
    this.nextslideshowId = nextslideshowId;

    $("#nextslideshow").click( function(e) {

        hideoriginal( this.originalslideshowId );

    } );

    this.showOriginal = function() {

        $( this.originalslideshow ).click(function(e) {

            shownext(this.nextslideshowId);

        });

    };

};

正如您所猜测的,this.originalslideshowId和this.nextslideshowId在试图从jQuery对象中读取属性时返回undefined。如何让他们从Slideshow类中读取正确的属性?

将此保存到变量中:

function Slideshow( originalslideshowid, nextslideshowId ) {
    var _this = this;

    this.originalslideshowId = originalslideshowid;
    this.nextslideshowId = nextslideshowId;

    $("#nextslideshow").click( function(e) {    
        hideoriginal( _this.originalslideshowId );    
    });

    this.showOriginal = function() {    
        $( this.originalslideshow ).click(function(e) {    
            shownext(_this.nextslideshowId);    
        });    
    };    
}

谢谢,杰森。在网上搜索了一个小时,在JS和jQuery中找不到任何关于管理作用域的信息!