Coder Social home page Coder Social logo

Comments (10)

heapwolf avatar heapwolf commented on June 12, 2024

All libraries generally use at least one object in the global namespace. Its perfectly acceptable for an application to have a few variables in the global namespace, since the application developer has oversight into the involved components.

Conversely, it is potentially dangerous for a library to increase the surface area of the global namespace, since a library author has no idea what other variables will already be there. The constructor Plates is a pretty safe name.

from plates.

Phoscur avatar Phoscur commented on June 12, 2024

Okay, maybe the topic name is not correctly chosen.

My problem is that you are mixing node specific code with that global variable creation. And when you use a tool like browserify to include plates, you lose plates in the wrapping it creates.
This is a case where Plates should export on exports, but process is not defined.
Please use:

;var Plates = !exports ? {} : exports;

or

;var Plates = (!module && !exports) ? {} : exports;

Reopen!

from plates.

heapwolf avatar heapwolf commented on June 12, 2024

The problem with this is that its far too likely for exports or module to be defined in the user's global namespace. Alternatives?

from plates.

Phoscur avatar Phoscur commented on June 12, 2024

At include time? That sounds like some pretty bad style of polluting the global namespace, who does that? Ofc my proposal is not idiotproof.

;var Plates = (typeof require == 'function' && module && exports) ? exports : {};

from plates.

heapwolf avatar heapwolf commented on June 12, 2024

I think we are crossing wires. I am talking about the client side. The client side it is very easy for someone to have those variables defined. Of course its bad style, but its more likely than an object named process with a property called title. Someone can also have a client side function called require... Let's think about it some more.

from plates.

Phoscur avatar Phoscur commented on June 12, 2024

Well IMO using Plates and having a require function and module and exports objects is basically as unlikely as having a process object with a title containing "node". Also this risk is far less important than the drawback it has.

An alternative way to go would be giving out different files for browser and nodejs use.

Let's think about it some more.

Why isn't this open then?

from plates.

heapwolf avatar heapwolf commented on June 12, 2024

A library that exports a single global object does not polluting the global namespace. If you are concerned about browserify please create a test that demonstrates the issue.

from plates.

Phoscur avatar Phoscur commented on June 12, 2024

It's pretty simple what browserify does:
warp a function around Plates

function(require, module, exports, __dirname, __filename) {
var Plates = {}
[...]
}

execute the function -> oh noes, Plates got garbage collected.

I think I'm just going to fork Plates and stop annoying you.

from plates.

heapwolf avatar heapwolf commented on June 12, 2024

I know what browserify does, i asked you to write a test for it. If you cant make a tangible case for your issue i cant help.

from plates.

Phoscur avatar Phoscur commented on June 12, 2024

I don't really have any idea how a test for this should look like.

from plates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.