Wikipedia:Reference desk/Archives/Computing/2016 November 10
{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|
Javascript: preventing anonymous variable member names from clashing with parent scope
I'm just learning Javascript and having a little difficulty instantiating anonymous objects with variable names that shadow those of the parent scope. Suppose you had something like this:
function example(parameters)
{
return parameters.foo + parameters.bar;
}
function test
{
var foo = 67;
var bar = 163;
// ...do something with foo and bar here, and then...
var baz = example({ foo: this.foo, bar: this.bar }); // Error!
}
What's the right syntax to do that sort of thing? Earl of Arundel (talk) 04:30, 10 November 2016 (UTC)
: First of all, you're missing a pair of parentheses after function test
. Within the test
function, this
refers to the Window
object, not the function itself, so this.foo
and this.bar
are both undefined
. If you just write var baz = example({ foo: foo, bar: bar });
then it should work as you expect. AndrewWTaylor (talk) 09:25, 10 November 2016 (UTC)
:: Right! Very simple. Well, thanks so much for the help. Earl of Arundel (talk) 14:28, 10 November 2016 (UTC)
Stable IPv6s
Do they exist? My experience with IPv6s is only with dynamic ones, where the same person is assigned to various IPs in a range of trillions or quadrillions of addresses, but I don't have significant amounts of experience. Nyttend (talk) 18:22, 10 November 2016 (UTC)
- Yes... or at least they should. [https://tools.ietf.org/html/rfc4941 RFC4941] says {{tq|Devices implementing this specification MUST provide a way for the end user to explicitly enable or disable the use of temporary addresses}}, which means that there should be an option to get a static address (if you are using a fixed address point; I do not think there is a way to keep the same IPv6 on a mobile terminal that moves around).
:Notice though that (1) [https://code.google.com/p/android/issues/detail?id=31102 Android violated] (and maybe is still violating) that RfC; (2) the default configuration on most systems may still be dynamic addresses, and few change the default configuration. TigraanClick here to contact me 18:38, 10 November 2016 (UTC)