knockout.js - DukeScript: How do native calls into JavaScript work? -


i'm struggling understand how "native method" calls in dukescript work. in particular, ones no body specified in @javascriptbody annotation. for example:

@javascriptresource(value = "userentrycomponent.js") public final class userentrywidget {      private userentrywidget() {     }      @javascriptbody(args = {}, body = "")     public static native void registercomponent(); } 

where "registercomponent()" method defined? in knockout there's javascript function called "ko.components.register". "registercomponent" must sort of wrapper around "ko.components.register".

another example of native method call without body here:

@javascriptresource("jquery-1.11.0.min.js") public class jquery {      @javascriptbody(args = {},body="")     public static native void init();    } 

so, in case, what's "init()"? java method or javascript function?

i understand why code looks magical. if try comment out init method, should see error during javac complication:

compilation error :  ------------------------------------------------------------- jquery.java:[10,8] @ least 1 method needs @javascriptbody annotation. otherwise not guaranteed resource ever loaded 

the error line line @javascriptresource usage. init method definition empty , nothing. once called, enforces load of resource defined in @javascriptresource.

in knockout case, ko.components.register defined knockout.js resource file. method name registercomponent can arbitrary, there trigger load of knockout.js resource.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -