小编Eig*_*rew的帖子

在JavaScript中调用"超类"构造函数

我刚刚进入JavaScript,我对它的面向对象行为感到困惑.我只是想创建一个类Point2Dx,y成员和一个扩展它Point3D带班x,y,z的成员.我试图实现的行为是这样的,让我们在C#中说:

class Point2D
{ 
   int x, y;
   public Point2D(int x, int y) { this.x = x; this.y = y; }
}
class Point3D : Point2D
{
    int z;
    public Point3D(int x, int y, int z) : base(x, y) { this.z = z; }
}
Run Code Online (Sandbox Code Playgroud)

我读了很多东西,但我似乎并没有真正找到我想要的东西.这是我到目前为止所做的:

function Point2D(x, y) { this.x = x; this.y = y; }
Point2D.prototype.constructor = Point2D;
function Point3D(x, y, z) { Point2D.prototype.constructor.call(this); this.z …
Run Code Online (Sandbox Code Playgroud)

javascript polymorphism inheritance

9
推荐指数
1
解决办法
7203
查看次数

部分应用和关闭

我被问到部分功能应用程序和闭包之间的关系是什么.我会说没有,除非我忽略了这一点.假设我正在用python编写,我有一个非常简单的函数MySum定义如下:

MySum = lambda x, y : x + y;
Run Code Online (Sandbox Code Playgroud)

现在我正在修复一个参数以获得一个较小arity的函数,如果我使用相同的参数(部分应用程序)调用它,则返回MySum返回的相同值:

MyPartialSum = lambda x : MySum(x, 0);
Run Code Online (Sandbox Code Playgroud)

我可以用C做同样的事情:

int MySum(int x, int y) { return x + y; }
int MyPartialSum(int x) { return MySum(x, 0); }
Run Code Online (Sandbox Code Playgroud)

所以,愚蠢的问题是:有什么区别?为什么我需要关闭部分应用程序?这些代码是等价的,我不知道闭包和部分应用的界限是什么.

closures partial

8
推荐指数
2
解决办法
2585
查看次数

调用图IEnumerator

我必须为表达式实现一个调用图Id = Id(Param);,这不是问题.

现在我必须实现一个枚举器,它一次列出一个满足依赖顺序的调用中的所有拓扑排序.

而这就是麻烦.

这是调用图的一个简单节点:

class CallGraphNode
{
    private string name;
    public List<CallGraphNode> dependents = new List<CallGraphNode>();
    public int dependencies;
    private bool executed = false;
    public bool Executable { get { return dependencies == 0; } }
    public bool Executed { get { return executed; } set { executed = value; } }

    public CallGraphNode(string name)
    {
        this.name = name;
        dependencies = 0;    
    }

    public override string ToString()
    {
        return name;
    }

    public void AddDependent(CallGraphNode n)
    { …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
288
查看次数

标签 统计

c# ×1

closures ×1

inheritance ×1

javascript ×1

partial ×1

polymorphism ×1