0
function Something(s, e)

What is the difference between s and e?

As instance,

function Validation(s, e) {
if (e.value == null)
e.isValid = false;
var name = String(e.value);
if (name.trim() == "" || name == undefined)
e.isValid = false;
}

If I use "s" instead of "e" in above Javascript code, it does not work.

When do we use s?
When do we use e?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Soner Sevinc
  • 400
  • 4
  • 19

4 Answers4

3

These parameters just are aliases of the pre-defined signature. It looks like that some of your questions related to DevExpress ASP.NET products. If so, you'd better refer to the Client-Side Events documentation to regarding this:

  • s parameter represents the client object that raises the event. The "s" (sender) parameter encapsulates all available client-side functionality (for the ASPxGridView class - it is the ASPxClientGridView class)
  • e parameter represents the event argument, which typically contains event-specific information.
Mikhail
  • 9,186
  • 4
  • 33
  • 49
1

It is all about calling the function.

That means if you call the validation function like Validation("1","2"); then inside the function, s=1 and e=2. It just takes these arguments as their order.

I guess their types are different, that is why you get an error.

If you still has problems about that, just type your mail as comment to this answer and let me explain to you in Turkish.

Emre Acar
  • 920
  • 9
  • 24
0

I'm not 100% sure about what that code is supposed to do, but I can point out a few of things:

  1. I'm not sure how you would call that function with e, but without s . . . parameters are determined by their placement in the function definition, so, in this case, since it is defined as function Validation(s, e), if you put only one parameter in, the function will consider it to be s. Technically, you could call the function like this: Validation(undefined, e), but even then you are still sort of "defining" s as undefined.
  2. IF you are saying that it doesn't work when you supply s, but not e, that is because leaving out e when you call the function, will make the value undefined. As soon as you try e.value, JS will throw the error "TypeError: e is undefined".
  3. s does not appear to be used in the function, so there is nothing that can be known about it, other than it is a parameter of the function, but you can deduce from looking at the function that e is an object with, at least to properties: value and isValid. Additionally you can surmise that isValid is intended to store a Boolean value, given that it is assigned values of false in the code, but, since the sole use of value is as the parameter of a String constructor (which can accept a TON of different value types as a parameter), there's no real way of knowing what type of data it is intended to hold.

That's all that I can think to offer at the moment.

talemyn
  • 7,822
  • 4
  • 31
  • 52
0

Parameter names are arbitrary. If you switch all occurrences of s and e in your function, it will still work as intended:

function Validation(e, s) {
if (s.value == null)
s.isValid = false;
var name = String(s.value);
if (name.trim() == "" || name == undefined)
s.isValid = false;
}

You may also consider using longer names like inputData instead of single letters in order to make it clearer what your parameters are for.

Remember: it's not the name of a variable that makes it work in a special way. It's the programmer who's supposed to give a variable a name that explains how it works.

That said, I'd suggest you start giving a look at some of the basics of Javascript. Those links may help you:

A more advanced discussion about variable names can be found here: What characters are valid for JavaScript variable names?.

Community
  • 1
  • 1
GOTO 0
  • 42,323
  • 22
  • 125
  • 158