-1

Does this (below) consume:

a) A little bit more - but that's obvious. Not enough to be a concern though. b) Vast swathes of memory - no no no!

getFoo =                // Lowercase alias because of new style guide
GetFoo = function ()
{
};

Thanks.

Richard
  • 4,809
  • 3
  • 27
  • 46
  • 1
    Can you explain "`Lowercase alias because of new style guide`"? In JS you should capitalize the first letter in constructor functions' names only, everything else should start with a small letter. – Teemu Feb 02 '14 at 17:29
  • @Teemu I've chosen to try and make all my function names start with lowercase letters, but still want to preserve bc. So the function can be called using getFoo(); or GetFoo(); and both will work - without me having to write two functions. – Richard Feb 02 '14 at 17:32
  • 1
    This seems a good first step for obsfucation. Some people prefer to perform obsfucation with a tool, and as the last step before publishing. – GameAlchemist Feb 02 '14 at 17:35
  • @GameAlchemist I'm trying to bring some sort of order to my API whilst t the same time preserving backward compatibility – Richard Feb 02 '14 at 17:42
  • 1
    In your case, the memory use is not relevant : the real issue is that it is not a good start for your new programming style. In your place i would consider that older app will use older API version with its syntax, and new apps will use latest version with new syntax. Breaking change. – GameAlchemist Feb 02 '14 at 18:06
  • "Breaking change" - I don't like that :-) – Richard Feb 02 '14 at 18:08

1 Answers1

0

As many commmentors have pointed out, I was wrong about it using double the memory. Option a, a tiny bit more memory usage, would happen, but that's all. Your current solution is OK. Sorry all, I learn something...

rvighne
  • 20,755
  • 11
  • 51
  • 73
  • No, I mean [ES5 getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/get). They're a language feature. See the link I provided. – rvighne Feb 02 '14 at 17:46
  • The function in question is itself a getter. Here's more: obj = new Foo; value = obj.get('somePropety'); instead of obj = new Foo; value = obj.Get('somePropety'); – Richard Feb 02 '14 at 17:47
  • @Richard We're talking about two different kinds of getters. `getFoo` can be a getter function or a normal function; this code doesn't care. In this code I'm using *[ES5 getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/get)*. They have nothing to do with *getter functions*. – rvighne Feb 02 '14 at 17:50
  • 4
    Uhm what? Why would it consume double the memory? You are not creating two functions! It's still one function which is referred to by two variables. – Felix Kling Feb 02 '14 at 17:53
  • @FelixKling JS functions are Objects. You can clone objects by simply doing `var b = a`. The code `a=b=c` is no different from `a=c;b=c`. Try it out in a console. – rvighne Feb 02 '14 at 17:54
  • 1
    @rvighne: You are wrong, you cannot "clone" objects like this. Both variables will still refer to the same object, and you can easily proof this by running `b === a`. Sorry, but you are way off. See http://stackoverflow.com/q/122102/218196 for how to clone objects. Think about it: if it really were possible to clone objects via assignments, then it wouldn't be necessary to use the techniques mentioned in that question. – Felix Kling Feb 02 '14 at 17:56
  • -1. Why not use getters in production code? Because old browsers do not support them. Also, a getter property should not be prefixed with `get`… – Bergi Feb 02 '14 at 18:01
  • Irrelevant answer to a not-so-relevant question. It seems not knowing the distinction between duplicating a reference and copying an object is not something that would stop someone from posting. – GameAlchemist Feb 02 '14 at 18:02