【问题标题】:Will jQuery support OOP concepts?jQuery 会支持 OOP 概念吗?
【发布时间】:2018-05-30 11:09:09
【问题描述】:

我在 jquery 中使用此代码来创建一个类并使用类变量,任何人都可以在我运行时帮助我如何做到这一点,浏览器上没有显示任何内容。并且类名应该是通用的。

我想为简单的算术运算构建通用类......

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    var simpleClass = {

        testAttribute : "test", // atttribute

        testMethod : function() //method
        { 
            return testAttribute; } 

    };
    var simpleClassObj = new simpleClass();
    simpleClassObj.testAttriute;
</script>

【问题讨论】:

    标签: jquery html oop


    【解决方案1】:

    线

    simpleClassObj.testAttriute;
    

    什么都不做,因为您只是在写属性的名称,没有将其分配给变量或将其回显到屏幕或控制台。

    此外,您应该查找任何有关 JS 类的教程,因为这不是您在 JS 中声明类的方式。它应该看起来像这样:

    var simpleClass = function() {
    
        this.testAttribute = "test"; // atttribute
    
        this.testMethod = function() //method
        {
            return this.testAttribute;
        };
    
     };
    
    var simpleClassObj = new simpleClass();
    alert(simpleClassObj.testMethod());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多