如何使用nativescript javascript扩展?

时间:2015-06-21 19:46:49

标签: nativescript

我按照此guide继承了一个类,但是因dalvik.system.NativeStart.main(native method)错误而崩溃

var MyDatePicker = android.widget.DatePicker.extend({
    init: function() {
        var isConstructor = arguments[arguments.length - 1];
        if (isConstructor) {
            // we are called from Java constructor
            console.log('con')
        } else  {
            // we are called from Java init method
            console.log('init');
        }
    }
});

var foo = new MyDatePicker();

1 个答案:

答案 0 :(得分:1)

根据Android文档(http://developer.android.com/reference/android/widget/DatePicker.html),DatePicker构造函数至少需要一个参数(上下文)。尝试传递它,例如

var foo = new MyDatePicker(context);