Skip to content

对int(), number(), String()的强转API支持有问题 #7

@nofastfat

Description

@nofastfat

异常是由如下代码触发的:

if (scope[vname] is Function) {
       return (scope[vname] as Function).apply(scope, explist);
 }
 throw new Error(scope + "不存在" + vname + "方法");

API中虽然预设了int()等3个强转的API,

Script.addAPI("Number",Number);
Script.addAPI("int",int);
Script.addAPI("String",String);

但是!这样子写进去,scope["int"]取出来的是一个Object,并不是Function
(parseInt 方法是Function)

所以。。。。
我在throw前面临时加了这个处理:

        switch (vname) {
            case "int":
                return int(explist[0]);
            case "Number":
                return Number(explist[0]);
            case "String":
                return String(explist[0]);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions