Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class function gets an error #12

Closed
erickyim opened this issue May 26, 2015 · 4 comments
Closed

class function gets an error #12

erickyim opened this issue May 26, 2015 · 4 comments

Comments

@erickyim
Copy link

I add a class function hello() to demo.js:

defineClass('JPTableViewController : UITableViewController', {
    ...
    tableView_heightForRowAtIndexPath: function(tableView, indexPath) {
        return 60
    }
}, {
    //class method definitions
    hello: function() {
        console.log("hello");
        return "I'm JPTableViewController"
    }
})

And called hello():

defineClass('JPViewController', {
    handleBtn: function(sender) {
        var tableViewCtrl = JPTableViewController.alloc().init();
        console.log(JPTableViewController.hello());

        self.navigationController().pushViewController_animated(
            tableViewCtrl, YES)
    }
})

hello() works, (it prints logs,) but rises an error:

2015-05-26 19:29:46.642 JSPatchDemo[31797:867980] JSPatch.log: hello
2015-05-26 19:29:46.643 JSPatchDemo[31797:867980] JSPatch.log: I'm JPTableViewController
2015-05-26 19:29:46.647 JSPatchDemo[31797:867980] TypeError: null is not an object (evaluating 'self.__c')
2015-05-26 19:29:46.647 JSPatchDemo[31797:867980] *** Assertion failure in +[JPEngine startEngine], /Users/path/JSPatch/JSPatch/JPEngine.m:111
2015-05-26 19:29:46.650 JSPatchDemo[31797:867980] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'js exception: TypeError: null is not an object (evaluating 'self.__c')'
...

I notice in #10 you said "By now, JSPatch can't add method to an OC class if the method not exists in OC". Thanks for your work~

@bang590
Copy link
Owner

bang590 commented May 27, 2015

@cyvoit That's an other bug, also fixed in 653074f

@bang590 bang590 closed this as completed May 27, 2015
@erickyim
Copy link
Author

Great! I still use example above.
And called hello():

defineClass('JPViewController', {
    handleBtn: function(sender) {
        var tableViewCtrl = JPTableViewController.alloc().init();

        self.navigationController().pushViewController_animated(
            tableViewCtrl, YES)
        console.log("self is " + self.description());
        console.log(JPTableViewController.hello());
        console.log("self is " + self.description());
    }
})

It works and no errors.

But called hello() like this:

defineClass('JPViewController', {
    handleBtn: function(sender) {
        var tableViewCtrl = JPTableViewController.alloc().init();
        console.log(JPTableViewController.hello());
        console.log("self is " + self.description());
        self.navigationController().pushViewController_animated(
            tableViewCtrl, YES)
    }
})

It logs:

2015-05-28 10:15:50.969 JSPatchDemo[10737:267688] JSPatch.log: hello
2015-05-28 10:15:50.970 JSPatchDemo[10737:267688] JSPatch.log: I'm JPTableViewController
2015-05-28 10:15:50.970 JSPatchDemo[10737:267688] JSPatch.log: self is JPTableViewController
2015-05-28 10:15:50.970 JSPatchDemo[10737:267688] +[JPTableViewController navigationController]: unrecognized selector sent to class 0x7fe9b2d2e0b0

bang590 added a commit that referenced this issue May 28, 2015
@bang590
Copy link
Owner

bang590 commented May 28, 2015

@cyvoit Fixed, that's a stupid bug I made - -! Thank you!

@erickyim
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants