Trying to use resemble.js within a server-side PhantomJS script is throwing undefined errors and no amount of logging will penetrate past {object Object}. Patterning after the phantom/examples/universe.js file, I tried turning the original resemble.js file :
(function (_this) {
_this['resemble'] = function (fileData) {
...
}
}(this));
into
exports.create = function () {
(function (_this) {
_this['resemble'] = function (fileData) {
...
}
}(this));
};
as well as
exports.create = function () {
resemble = function (fileData) {
...
}
};
First off, what the hell does that dangling (this)
do? Secondly, how can I log that object? Finally, what is the proper way of wrapping up that file?
Thanks!
For running resemble from within phantomJS, check out https://github.com/Huddle/PhantomCSS . Clone and you are immediately up and running. Replace phantomjs.exe with the correct binary for your system if you aren't on windows.
You haven't quite pasted the (this)
at the end correctly. Anyways, it's an IIFE . The first argument of the function, _this
is just a scoped copy of the (this)
at the end.
You can log it simply by dumping _this
within the function body or by logging this
outside of the function body.
Also see What is this construct in javascript? and Advanced Javascript: Why is this function wrapped in parentheses? [duplicate]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.