为什么我不能直接访问jLib.method()?

时间:2014-05-14 16:01:04

标签: javascript prototype instance anonymous-function

这是我的第一个问题......

我将使用类似jQuery的语法开发自己的javascript库。 我写了这段代码:

(function(window)
{
    // Returns new instance
    var jLib = function( args ) { return new MyLib(args); };

    var MyLib = function( args )
    {
        // [...]
        /* This runs perfectly */

        return this;
    };

    /* I can't understand why jLib.byId() is undefined! */
    MyLib.lib = MyLib.prototype = {
        byId: function( id ) { return MyLib("#" + id); },

        /** Other code **/
    };

  // Add it to the window object
  if(!window.jLib) window.jLib = jLib;
})(window);

但是如果我尝试运行jLib.byId()它会抛出" undefined不是函数"。

你能解释一下为什么吗?

0 个答案:

没有答案
相关问题