1

In all of the demos I have seen thus far, Web Workers and Web Sockets apis seemed to use the "new" keyword in JavaScript. Is there another way to use these powerful tools without using the new keyword?

Matt
  • 5,553
  • 5
  • 24
  • 32
  • You'll have to give some kind of context to what you're talking about. Does _new_ mean "newfangled thing" or does _new_ mean the C++ keyword for allocating memory? (And who would write web services code in C++?) – sarnold Mar 22 '12 at 00:25
  • The "new" keyword means that you're creating an object in javascript, that's the one I'm talking about – Matt Mar 22 '12 at 00:29
  • Ah, a third interpretation I hadn't considered. Please [edit] your question to be more clear what problem or curiosity you're specifically trying to solve... – sarnold Mar 22 '12 at 00:32
  • That's how you create a new object, other than Object.create. What's the problem with `new` – tkone Mar 22 '12 at 00:33
  • @sarnold web workers and web sockets are new JavaScript APIs. – tkone Mar 22 '12 at 00:34
  • I remember reading that the "new" keyword was potentially dangerous – Matt Mar 22 '12 at 00:40
  • @tkone: I'm far more familiar with the server-side functionality; there's no point having a websocket unless you've got a server for it to talk with. :) – sarnold Mar 22 '12 at 00:51

1 Answers1

2

new is not dangerous. It returns a new object settings its prototype to that objects prototype and calling its constructor.

No where in the Mozilla dev docs does it say it's dangerous.

As answered this so question: is new harmful

I wish crockford et al wouldn't have said that because it gets boiled down to saying new is harmful and don't use it.

Use new. But don't forget to use new.

Community
  • 1
  • 1
tkone
  • 22,092
  • 5
  • 54
  • 78