Open lukas-mertens opened 6 years ago
I ran into this as well, I just haven’t had a chance to make a pr- pdfObject
is not a function (despite the sample code implying that it is), it’s a property that runs a getter method and returns a promise. Just do:
pdfAssemblerObj.pdfObject.then(...)
Several of the things you would expect to be methods are implemented as properties! Look in the source; if a “method” is declared prefixed with get
and a space it’s actually a property.
Explanation of js getters, since they’re not very commonly used: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
Thank you, you saved my day! I made a pull request (#1), that adds an explanation to the Readme. That was the last thing I had to fix, I am now ready for production/open source 🎉
I won't close the issue for now, because I think it would be a good idea to switch to methods. What do you think?
I merged your pull request to fix the readme, @lukas-mertens - thanks!
No problem!
I'm reopening this because I think the comment about "Several of the things you would expect to be methods are implemented as properties!" is a valid criticism I'd like to address.
The library currently has three properties:
Personally, I don't have a preference about whether these are methods or properties. I think it does make sense to make them methods, primarily for consistency. On the other hand, changing them would break backwards compatibility for people already using the library and expecting them to be properties.
Perhaps a good transitional solution would be to replace them with a new functions with different names, like so:
I would update the documentation to inform people to use the functions, but also leave the old properties in place for a while so as to maintain backward compatibility for a few more versions.
Thoughts? Alternate suggestions?
Is for example the number of pages calculated when accessing the property numPages
or is it calculated by some other function before that? Because a property implies that it's calculated before accessing the property, a function would imply that it's being calculated when calling the function. If countPages()
would just return some pre-calculated value, I would just leave it as it is. But the documentation should be updated in that case:
Renaming the methods wouldn't be a good idea I think... I would do it like this:
<button>
Click me
</button>
<div>
Current Time (1): <span id="1"></span><br>
Current Time (2): <span id="2"></span>
</div>
var exampleObject = {
getTime: function() {
return new Date().toLocaleString();
}
}
$("button").click(function() {
$("#1").html(exampleObject.getTime);
$("#2").html(exampleObject.getTime());
});
Hi! Thank you for developing pdfassembler, it's exactly what I need. I've got a problem with your minimal working example from the Readme.md. I use Browserify and Babel to support all browsers and to use
on the client side.
This is my code:
Whenever I try to execute it, it throws the error
in firefox (just the beginning of the error) and
in chrome. When I print out the
pdfAssemblerObj
usingit gives me the object
Did you change anything about the API? Or what did I do wrong?
Edit: I don't use TypeScript. Could that be a problem?