如何在经典的jscript中创建一个类? [英] how to create a class in classic jscript?

查看:51
本文介绍了如何在经典的jscript中创建一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用经典的jscript创建一个类? (不是jscript.net)

how to create a class in classic jscript? (not jscript.net)

而且,如何引用此类?

我尝试过

class someclass {


}

但它不起作用.

推荐答案

没有类似的类,但这是一个简单的示例,说明了如何获得基本的面向对象功能.如果这是您所需要的,那就太好了,但是如果您追求类的其他功能(例如继承),那么一个比我自己知识渊博的人将需要帮助.

There are not classes as such, but here's a simple example of how to get basic object-oriented functionality. If this is all you need, great, but if you're after other features of classes, such as inheritance, someone more knowledgeable than myself will have to help.

function SomeClass(n) {
    this.some_property = n;
    this.some_method = function() {
        WScript.Echo(this.some_property);
    };
}

var foo = new SomeClass(3);
var bar = new SomeClass(4);
foo.some_method();
bar.some_property += 2;
bar.some_method();

这篇关于如何在经典的jscript中创建一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆