text Metaobjects addCodeToGenericPrototype和AddCodeFromMetaobject

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Metaobjects addCodeToGenericPrototype和AddCodeFromMetaobject相关的知识,希望对你有一定的参考价值。

package metaobjectTest

/*
   @addCodeFromMetaobject  is in prototype Array. The annotation addCodeToGenericPrototype
   gives the code to be added to the array of prototype AddCodeFromMetaobject.
*/

@addCodeToGenericPrototype("Array"){*

    func sumAll -> Int {
        var Int s = 0;
        for elem in self {
            s = s + elem getValue;
        }
        return s
    }
*}
object AddCodeFromMetaobject
        // methods getValue and setValue: will be added to prototype
    @property Int value = 0;
    @init(value)

    func run {
        var array = [ 
            AddCodeFromMetaobject(1), AddCodeFromMetaobject(2),
            AddCodeFromMetaobject(3) ];
            /* method sumAll will be added to Array<AddCodeFromMetaobject> by 
               metaobject addCodeFromMetaobject. This method was passed by
               annotation addCodeToGenericPrototype of this prototype 
               (AddCodeFromMetaobject)
            */
        assert array sumAll == 6;
    }
    
end

以上是关于text Metaobjects addCodeToGenericPrototype和AddCodeFromMetaobject的主要内容,如果未能解决你的问题,请参考以下文章

如何将 Qt 属性与自定义类一起使用?

库魔法。 text/plain 而不是 text/javascript text/css

<!-- text --> 和 /* text */ 注释有啥区别?

VB中 如何复制Text1.text的字体到剪贴板? 如何剪切?

VB 加减乘除

text-decoration:[ text-decoration-line ] || [ text-decoration-style ] || [ text-decoration-color ]