代码之家  ›  专栏  ›  技术社区  ›  Fatih Acet

Firebug构造函数与用户函数

  •  2
  • Fatih Acet  · 技术社区  · 15 年前

    from here

    红色加粗文本点“构造函数函数”

    绿色粗体文本表示“用户功能”。

    这两种类型的函数有什么区别?

    2 回复  |  直到 9 年前
        1
  •  1
  •   Community Mohan Dere    9 年前

    这个 jQuery 功能 $ 只是指 jQuery公司

    var jQuery = function( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context );
    },
    …
    jQuery.fn = jQuery.prototype = {
        init: function( …
    

    在定义构造函数时,可以重现这种行为(粗体红色) 在其原型对象中添加一些内容,如

    var testFunc = function () {
        /* nothing so far */
    };
    
    testFunc.prototype.baz = function () {
        /* nothing, this gets boring */
    };
    

    testFunc.prototype.baz = 4;
    

    注意,这不符合 constructor function car 将被涂成绿色,而不是红色。此外,请参见 The Benefits of JavaScript Prototype

        2
  •  1
  •   johnjbarton    15 年前

    如Marcel的示例所示,Firebug标记类型为“function”且具有属性“prototype”且至少有一个子属性为“userClass”的对象

    http://code.google.com/p/fbug/source/browse/branches/firebug1.7/content/firebug/dom.js#431

    在Javascript中实际上没有“构造函数”这样的东西,只有可以用作构造函数的函数。任何函数都可以用来创建对象,但只有当函数具有原型时才真正有趣。