一段代码的疑问

2019-03-25 13:44|来源: 网路

Function.prototype.method = function(name, func) {
    this.prototype[name] = func;
    return this;
};

// A (rather complex) function that allows you to gracefully inherit
// functions from other objects and be able to still call the  'parent'
// object's function
Function.method('inherits', function(parent) {
    // Keep track of how many parent-levels deep we are
    var depth = 0;

    // Inherit the parent's methods
    var proto = this.prototype = new parent();

    // Create a new 'priveledged' function called 'uber', that when called
    // executes any function that has been written over in the inheritance
    this.method('uber', function uber(name) {

        var func; // The function to be execute
        var ret; // The return value of the function
        var v = parent.prototype; // The parent's prototype

        // If we're already within another 'uber' function
        if (depth) {
            // Go the necessary depth to find the orignal prototype
            for ( var i = d; i > 0; i += 1 ) {
                v = v.constructor.prototype;
            }

            // and get the function from that prototype
            func = v[name];

        // Otherwise, this is the first 'uber' call
        } else {
            // Get the function to execute from the prototype
            func = proto[name];

            // If the function was a part of this prototype
            if ( func == this[name] ) {
                // Go to the parent's prototype instead
                func = v[name];
            }
        }

        // Keep track of how 'deep' we are in the inheritance stack
        depth += 1;

        // Call the function to execute with all the arguments but the first
        // (which holds the name of the function that we're executing)
        ret = func.apply(this, Array.prototype.slice.apply(arguments, [1]));

        // Reset the stack depth
        depth -= 1;

        // Return the return value of the execute function
        return ret;
    });

    return this;
});



这段代码的作用,这个for循环是不是有问题
  for ( var i = d; i > 0; i += 1 ) {
                v = v.constructor.prototype;
            }

相关问答

更多
  • import java.awt.event.*; import javax.swing.*; public class FrameTest { public static void main(String[] args) { new F().setVisible(true); } } class F extends JFrame implements ActionListener{ JCheckBox a,b,c; JRadioButton d,e,f; ButtonGroup g; F(){ this.s ...
  • 求一段ajax代码[2023-05-08]

    无耐!我也在寻找相关的代码!Ajax搞得真是太神秘了!
  • 通过applicationContext.xml中配置 注入的! 仔细看一下你的applicationContext.xml你应该会发现这样一段内容 //声明bean ... //这里就是声明要注入前面注册的那个personService bean的实例
  • 定界符倒只有空格 不过你可以试试选中所有要缩进的代码 然后按TAB键 就能一次性缩进所有代码,大部分编辑器支持这个功能
  • 在idle中 按 alt+3 注释一段代码, 按 alt+4 则解除注释 。
  • 其实很简单,既然你用了VC,那你就无需编写窗口的代码,直接用MFC就可以了。 没分的话我也就不详细说明了,新建一个MFC AppWizard,选单文档程序,在CView这个类下添加messagebox()函数就可以完成了。Win32 Application 也能轻易实现。 如果自己编写这样一个窗口,你连楼上那个网站的代码都看不懂,那就算了吧。涉及到的概念太多了,而且必须有扎实的C++基础,还得掌握基本的API函数,MFC的透明程度又不是很高,学习有困难。
  • 异步复位的计数器。 当复位信号(rst_n)为低电平时,计数器复位(清零);否则,每个时钟的上升沿来临的时候,计数器加1,直到20000停止计数。
  • 求一段JAVA代码[2022-02-22]

    Image getImage(String filename){ URLClassLoader urlLoader=(URLClassLoader)this.getClass(). getClassLoader(); URL url=null; Image image=null; url=urlLoader.findResource(filename); image=Toolkit.getDefaultToolkit().getImage(url); MediaTracker mediatracker=ne ...
  • not ((a=ture)and(b=1))为TRUE 程序执行c:=1 结果 a=true b=0 c=1