Jquery原型与新函数冲突

Jquery prototype conflict with new function

本文关键字:函数 冲突 原型 新函数 Jquery      更新时间:2024-01-22

我正在尝试制作一个jQuery的补充库,但不是jQuery插件,也不是jQuery扩展:

第一个功能:

function w(id) {
    return $(id);
     }

它可以作为jQuery插件:

$.prototype.test = function(){
        console.log("testing");
        }
w("div").test(); // test

我想要的是这个,作为w()的原型函数,但不起作用:

w.prototype.test = function(){
        console.log("testing");
        }
w("div").test(); // test

谢谢,

它适用于:

w.prototype = jQuery.prototype;

谢谢SLaks!

但当它真的起作用时,就不起作用了:

w.prototype = {
    test: function(){
        console.log("testing");
    }}

现在它起作用了;

function w(id) {
    return $(id);
     }
w.prototype = jQuery.prototype;
w.prototype.extend({
    test:function(){
        console.log("testing");
        }
});

谢谢你的帮助!!!

您想要

w.prototype = jQuery.prototype;