English 中文(简体)
Java的遗产
原标题:Inheritance in Javascript

我正在处理一个简单的问题,以代表几个等级结构的类别。 有一个数据流,包含一些数据,数据可能因行类型而异。 单行只有所有权和日期,而长行可能包含所有权、说明、日期和形象。 我对贾瓦特来说不是新鲜事,但却不明白,这足以向前迈进。 举一个简化的例子,就是我如何在 Java写:

interface Row {
    View getView();
}

class BasicRow implements Row {
    private String title;
    private String description;

    public BasicRow(String title, String description) {
        this.title = title;
        this.description = description;
    }

    public View getView() {
        // return a View object with title and description
    }
}

class ExtendedRow implements Row {
    private String title;
    private String description;
    private Date date;
    private Image image;

    public ExtendedRow(String title, String description, Date date, Image image) {
        this.title = title;
        this.description = description;
        this.date = date;
        this.image = image;
    }

    public View getView() {
        // return a View object with title
        // description, date, and image
    }
}

在这里,联络处的改进很少,例如从基本Row延伸到新领域,而只界定新领域,加上超越了收听方法。

Java字没有接口或抽象的课堂,我恐怕我 have不去思考。 因此,我如何能够在有基类或接口的贾瓦特实施上述基本例子,以及两个从基类延伸的班级,每个班都有自己的具体行为。

任何要点都受到高度赞赏。

最佳回答

审视Douglas Crockford的文章:

Douglas Crockford is a senior JavaScript architect at Yahoo! He is well known for his work in introducing JavaScript Object Notation (JSON) - Wikipedia

这些条款是肌肉-reads,,我确信,它们将有助于你了解如何构建你的物体。

问题回答

“Javascript没有接口或抽象课堂,恐怕我 have不去思考,不是为了ty。

你们不需要使用无类型语言的接口。 接口仅允许汇编者确保某一物体具有某种功能,从而可以进行分类。 你用Javascript的话说,你想要和希望的方法(也确保你自己...... j获得帮助)就是说,你所说的目标具有这一功能。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签