How to write -webkit- in Javascript [duplicate] - javascript

This question already has answers here:
How to set the style -webkit-transform dynamically using JavaScript?
(5 answers)
Closed 7 years ago.
I need to change a property, which starts with -webkit-(and the other browser-specific statements), in Javascript. All of them start with dash. How am i supposed to write this?
In particular, the thing i need is -webkit-user-select. I know it should be something like webkitUserSelect, but no idea of what exactly.
Thanks

Just like you write any property that can't be used with dot notation:
element.style['-webkit-user-select'] = 'none';

Related

Javascript square brackets around method name [duplicate]

This question already has answers here:
What do square brackets around a property name in an object literal mean?
(2 answers)
Closed 5 years ago.
In the RxJs doc I found following code snippet:
[rxSubscriberSymbol]() {
return new SubjectSubscriber(this);
}
Its part of the Subject source code and is the first method right after the constructor.
So what do square brackets mean in this context?
those are symbols, which is very similar to defining properties but gives different accessibility and testability functionality and they are completely unique,
you can read a lot more about metaprogramming here,
Metaprogramming in ES6: Symbols and why they're awesome

Tricking Javascript variable [duplicate]

This question already has answers here:
Use dynamic variable names in JavaScript
(19 answers)
Closed 7 years ago.
I have a question that I could not find the answer, or perhaps cannot phrase the way it should...
I would like to trick javascript's way of handling variables...
Let's say in php I could do something like:
$test['usr_'.$id]=826
But when I try to do the same in Javascript/jQuery:
$("#usr_rank_h").val('rank_'+id);
It will output rank_826 instead of the value of the var rank_826
The equivalent idiom in javascript is actually
var id = 826;
var test = {};
test['rank_'+id] = 826;
Which gives you back an object of the form
{
'rank_826': 826
}
PS: I'm not sure why you are using jQuery in this case, are you getting the id from an input ?

Use of $ in regular method [duplicate]

This question already has answers here:
Why would a JavaScript variable start with a dollar sign? [duplicate]
(16 answers)
Closed 8 years ago.
I go over some code and I saw the following code
var failedExtPlugins = PluginR.$getFailPlug();
It seems that this time the $ is not refer to jquery object (yes I know that when you use Jquery you start with $) I guess,so what does it mean?
it look like regular method...but way the use $
It looks just like a part of a name. I like to use $ in a name of jQuery objects I have. Maybe author has some thoughts about that.
Its a jQuery wrapped object. $ObjectName reflects that its holding a reference of jQuery wrapped object of particular dom object.
For Example:
var $obj = $("#SomeId");

Reversing a variable in javascript [duplicate]

This question already has answers here:
How do you reverse a string in-place in JavaScript?
(57 answers)
Closed 8 years ago.
I don't really have a good way to explain in words what i wont to do.So im just going to have an example.
this is what the variable would be before.
var foo ="foo";
this is what i wont it be after.
var foo ="oof";
I hope that you under stand what i'm asking!
Thinks !
Try this:
var foo="start".split("").reverse().join("");

Call function programmatically/"by string" in coffeescript [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Dynamic object property name
I have a function that I need to call based on a user inputted data.
So for example, I have:
models.cat
models.dog
Now, I want to be able to call models.[my_str] where my_str = "snake". So the computer would think it is trying to execute models.snake. Is there a way to do this in javascript or better yet coffeescript?
You should be able to call it like so:
models[my_str]();
This should work in both Javascript and Coffeescript.

Categories