dojo.cookie update? - cookies

I am new to Javascript and Dojo. I apologize in advance if my question below has an obvious answer.
A cookie is set to be
var foo = "abcde";
dojo.cookie("bar", foo);
Later foo became foo = "abcdefghijk".
Is it possible to update dojo.cookie("bar") so that it always contains the most updated information of foo (i.e., must not change the cookie name, "bar")?
Thanks!

Simply do this:
var foo = "abcde";
dojo.cookie("bar", foo);
foo = "abcdefghijk";
dojo.cookie("bar", foo);
See example http://jsfiddle.net/JszB7/4/ and read about dojo cookie http://dojotoolkit.org/reference-guide/1.7/dojo/cookie.html

Related

How can I print the variable name itself in dart? [duplicate]

For Example, I have a variable like this.
var fooBar = 12;
I want a something like this in Dart lang.
print_var_name(fooBar);
which prints:
fooBar
How can I achieve that? Is this even possible?
Thank you.
There is no such thing in Dart for the web or for Flutter.
Reflection can do that, but reflection is only supported in the server VM because it hurts tree-shaking.
You need to write code for that manually or use code generation where you need that.
An example:
class SomeClass {
String foo = 'abc';
int bar = 12;
dynamic operator [](String name) {
switch(name) {
case 'foo': return foo;
case 'bar': return bar;
default: throw 'no such property: "$name"';
}
}
}
main() {
var some = SomeClass();
print(some['foo']);
print(some['bar']);
}
output:
abc
123

How to get a field object using its name in proto3

I am migrating schemas from proto2 to proto3 syntax. I want to eliminate extensions as they are not supported. Is it possible to get an object using a field name in proto3, similar to what MutableExtension does in proto2.
For example,
Schema in proto2 syntax
message Foo {
message Bar {
unint32 a = 1;
}
extend Foo {
Bar b = 1;
}
}
C++
Foo::Bar b_val = foo.MutableExtension(Foo::b);
Now in proto3, I could do this:
syntax="proto3";
message Foo {
message Bar {
unint32 a = 1;
}
Bar b = 1;
}
C++ code:
Foo::Bar b_val = foo.mutable_b();
However, I want to use the name Foo::b to get a Foo::Bar object. Is there a way to do this?
It's not clear why you need this but what you are asking for is kinda feasible.
Foo::b is a garden variety member function, which means that &Foo::b is a regular pointer-to-member-function.
So you can use it as such using the regular c++ syntax for these entities:
auto b_ref = &Foo::b;
Foo::Bar b_val = (foo.*b_ref)();

Should I duplicate test data and assert data?

The question is probably best asked with a simple example:
var myObj = { name: 'John' };
var copiedObj = ObjectCopier.copy(myObj);
copiedObj.name.should.equal('John'); // Hard code 'John' twice
copiedObj.name.should.equal(myObj.name); // Reference the original value
Is one method preferred over the other? Assuming the value passed in is what I expect to be returned, is there any harm in the 2nd assert? Does it even matter?
In more complex cases you won't be able to duplicate an object completely - and you wouldn't want to. it would be better written this way:
var OBJ_NAME = 'John'
var myObj = { name: OBJ_NAME };
var copiedObj = ObjectCopier.copy(myObj);
copiedObj.name.should.equal(OBJ_NAME);
this way you're not duplicating any code/defines, and you can also make tests such as:
myObj.name.should.equal(OBJ_NAME);
to test for the object copier not changing the original object either (which either of your lines won't test for).

How to alter Bootstrap's typeahead selected value?

I retrieve the selected typeahead value by using this method:
$('ul.typeahead li.active').data('value');
I then set this equal to a variable, like so,
var foo = $('ul.typeahead li.active').data('value');
However, if I try and do something like this:
var foo = $('ul.typeahead li.active').data('value').replace( /\([^\)]+\)$/, '' );
it won't seem to update the value of foo even though when I console.log(foo) it actually is showing the right value for foo.
Can you please tell me what I could do to resolve this?
Data returns an object and not a String
Try :
var foo = $('ul.typeahead li.active').data('value').first.replace( /\([^\)]+\)$/, '' );

Passing a struct to a function results in nested struct

When I pass a struct to a function that is expecting a struct, the function is nested inside another struct.
For example:
function getAnswerFromSO(struct question=StructNew()) {
writeDump(arguments.question);
}
CallinggetAnswerFromSO(question=myStruct); results in
question {
myStruct = {
text = 'foo',
subj = 'bar',
user = 1 }
};
** Obviously, this is not what a cfdump output looks like, but it illustrates the issue just the same.
Is there a way to prevent this nesting?
I can confirm that Ray's example works on CF9 as well.