如何动态加载java.lang.Math的函数

时间:2015-06-14 16:26:21

标签: java math dynamic methods loading

我需要动态加载java.lang.Math的函数,并在被选中时能够使用该函数。

我已经尝试过了,但它没有用。它给了我一个空指针异常。

<script>
    // Our person constructor
    function Person (name, age) {
        this.name = name;
        this.age = age;
    }
    // We can make a function which takes persons as arguments
    // This one computes the difference in ages between two people
    var ageDifference = function(person1, person2){
        return person1.age - person2.age;
    };
    // Make a new function, olderAge, to return the age of
    // the older of two people
    function olderAge(){
        if(alice.age > billy.age){
            return alice.age;
        }else{
            return billy.age;
        }
    }
    // Let's bring back alice and billy to test our new function
    var alice = new Person("Alice", 30);
    var billy = new Person("Billy", 25);
    console.log("The older person is " + olderAge(alice, billy));
</script>

0 个答案:

没有答案