Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goatify #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

goatify #8

wants to merge 2 commits into from

Conversation

sonnyp
Copy link
Owner

@sonnyp sonnyp commented Apr 17, 2016

just an idea, maybe a new module?

goatifyAll example

var pg = require('polygoat')
var fs = pg.goatifyAll(require('fs'))

// you can now use fs methods as promises
fs.readdir('/').then(function (result) {
  console.log(result)
})

// or with callbacks
fs.readdir('/', function (error, result) {
  console.log(error || result)
})

goatify example

var fs = require('fs')
var pg = require('polygoat')

// goatify a Node.js style function
var goatified = pg.goatify(fs.readdir)

// you can now use it as a promise
goatified('/').then(function (result) {
  console.log(result)
})

// or with a callback
goatified('/', function (error, result) {
  console.log(error || result)
})

for (var k in obj) {
if (obj.hasOwnProperty(k)) {
var v = obj[k]
if (typeof v === 'function') { // FIXME IIRC this fails on old browsers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what old browser would this fail in? This works at least back to IE6.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this would fail on previous major version of phantomjs (don't know what JavaScriptCore version it used though)

@benjamingr
Copy link

You should probably guard against doing goatifyAll multiple times on the same module.

@sonnyp
Copy link
Owner Author

sonnyp commented Apr 17, 2016

@benjamingr true, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants