Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/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
如何使用prototype扩展JQuery事件_Jquery_Prototype_Jquery Events - Fatal编程技术网

如何使用prototype扩展JQuery事件

如何使用prototype扩展JQuery事件,jquery,prototype,jquery-events,Jquery,Prototype,Jquery Events,我试图创建一个类来扩展jQuery.trigger和.on功能 此代码不起作用: var myclass = new $(); myclass.set = function (key, value){ this[key] = value; this.trigger('change', {key: key, value: value}); } myclass.on('change', function (e, param) { console.log("Hell

我试图创建一个类来扩展jQuery.trigger和.on功能

此代码不起作用:

var myclass = new $();
myclass.set =   function (key, value){
    this[key] = value;
    this.trigger('change', {key: key, value: value});
}

myclass.on('change', function (e, param) {
  console.log("Hello there");
});
myclass.set('student', 23);
我也试过这样做:

var MyClass = function () {
  this.set = function () {
     this[key] = value;
     this.trigger('change', {key: key, value: value});
  }
}

MyClass.prototype = new $();
var myclass = new MyClass();

myclass.on('change', function (e, param) {
  console.log("Hello there");
});
myclass.set('student', 23);
但这个代码是有效的:

var myclass ={
  set:  function (key, value){
    this[key] = value;
    $(this).trigger('change', {key: key, value: value});
  }
}

$(myclass).on('change', function (e, param) {
  console.log("Hello there");
});
myclass.set('student', 23);

在前面的代码中,我试图将一个“set”函数附加到$function的新对象上。

类似的内容,对吗

var MySubClass = function(){};
MySubClass.prototype = new $.Event() 

U应首先克隆$.Event,然后修改其prototype@EricSo,我已更新了问题。