Paper.js互操作性 [英] Paper.js Interoperability

查看:168
本文介绍了Paper.js互操作性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从页面中的HTML按钮调用paper.js函数,但我相信paper.js函数存在于它们自己的范围内。 paper.js文档提到互操作性,这听起来像是正确的直接,然后带我到一个页面,说即将推出:

http://paper.ws/tutorials/getting-started/paperscript-interoperability/



有谁知道我可以从我的HTML页面调用在paper.js脚本中创建的函数吗?

解决方案

缺少教程的道歉。我真的会投入一些时间来写作它。



去年我在邮件列表上回答了这个问题: https://groups.google.com/d/msg/paperjs/C6F0XFlplqM/_67AMqCR_nAJ


作用域PaperScript在全局范围内运行,并且可以访问全局范围的所有元素。在全局范围(= window)中运行的普通JavaScript不会看到这些PaperScopes,并且无法访问它们的变量。



有一个简单的交换解决方案两者之间的信息:简单地声明一个用于来回交换的全局结构,例如



  window.globals = {
someValue:10,
someFunction:function(){alert(globals.someValue); }
};




在您的PaperScript中,您只需通过'globals' ,因为它在窗口范围内:



  globals.someValue = 20; 
globals.someFunction();

以同样的方式,您可以使用普通JavaScript的这种结构。


I would like to call paper.js functions from HTML buttons in my page but I believe the paper.js functions exist in their own scope. The paper.js docs mention interoperability which sounds like the right direct by then take me to a page that says "coming soon":

http://paperjs.org/tutorials/getting-started/paperscript-interoperability/

Does anyone know how I can call a function created within a paper.js script from my HTML page?

解决方案

Apologies for that missing tutorial. I shall really invest some time into writing it finally.

I've answered this question on the mailing list last year: https://groups.google.com/d/msg/paperjs/C6F0XFlplqM/_67AMqCR_nAJ

Scoped PaperScript run inside the global scope, and have access to all elements of the global scope. The normal JavaScripts running in the global scope (= window) will not see these PaperScopes, and won't have access to their variables.

There is a simple solution to exchange information between the two: Simply declare a global structure that you use to exchange tings back and forth, e.g.

window.globals = {
    someValue: 10,
    someFunction: function() { alert(globals.someValue); }
};

In your PaperScript, you can then access this simply through 'globals', since it's in the window scope:

globals.someValue = 20;
globals.someFunction();

And in the same way, you can use this structure from normal JavaScript.

这篇关于Paper.js互操作性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆