3

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!

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
Indolering
  • 3,058
  • 30
  • 45
  • Not really, I was loading Casper as a module so that I could directly access Phantom objects. I was also hoping to use a batching system, so I could decouple the analysis from the actual benchmarking (trying to get a visual benchmark on ATF load times). – Indolering Mar 28 '13 at 17:11
  • It also looks like I must now use a non-phantom controller, as I can't switch proxies after loading the phantom test. – Indolering Mar 28 '13 at 17:12
  • Try https://github.com/kpdecker/node-resemble Node port of Resemble.js. – TechNikh Apr 29 '14 at 19:23

1 Answers1

1

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]

Community
  • 1
  • 1
ryan
  • 6,541
  • 5
  • 43
  • 68
  • (This) will help you identify current instance, where the function is called. – MarmiK Mar 12 '13 at 04:29
  • I was hoping to do my analysis out of band, using a batch system. I'll take a look, however. – Indolering Mar 28 '13 at 17:05
  • **Other answers would be appreciated, but the 100 goes to Ryan (unless he tells me to give it to someone else, as you DO have a lot of internet points already :D ), I just forgot to award the 50 point answer in time :/ ** – Indolering Mar 28 '13 at 17:13