You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/developer/model-driven-apps/clientapi/client-scripting-best-practices.md
+19-21Lines changed: 19 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ search.app:
17
17
---
18
18
# Best practices: Client scripting in model-driven apps
19
19
20
-
These are some of the best practice tips you could consider while writing your JavaScript code for model-driven apps.
20
+
The following are some of the tips you could consider while writing your JavaScript code for model-driven apps.
21
21
22
22
## Define unique JavaScript function names
23
23
@@ -26,35 +26,33 @@ When you write functions that will be used in JavaScript libraries, your functio
26
26
-**Unique function prefix**: Define each of your functions using the standard syntax with a consistent name that includes a unique naming convention, as shown in the following example.
27
27
```JavaScript
28
28
functionMyUniqueName_performMyAction()
29
-
{
30
-
// Code to perform your action.
31
-
}
29
+
{
30
+
// Code to perform your action.
31
+
}
32
32
```
33
33
-**Namespaced library names**: Associate each of your functions with a JavaScript object to create a kind of namespace to use when you call your functions as shown in the following example.
34
34
```JavaScript
35
-
//If the MyUniqueName namespace object isn’t defined, create it.
36
-
if (typeof (MyUniqueName) == "undefined")
37
-
{ MyUniqueName = {}; }
38
-
// Create Namespace container for functions in this library;
39
-
MyUniqueName.MyFunctions = {
40
-
performMyAction: function(){
41
-
// Code to perform your action.
42
-
//Call another function in your library
43
-
this.anotherAction();
44
-
},
45
-
anotherAction: function(){
46
-
// Code in another function
47
-
}
48
-
};
35
+
var Sdk = window.Sdk || {};
36
+
(function () {
37
+
this.formOnLoad = function () {
38
+
// Code to perform your actions.
39
+
}
40
+
this.attributeOnChange = function () {
41
+
// Code to perform your actions.
42
+
}
43
+
this.formOnSave = function () {
44
+
// Display an alert dialog
45
+
}
46
+
}). call(Sdk);
49
47
```
50
48
51
49
Then when you use your function you can specify the full name. The following example shows this.
52
50
53
51
```JavaScript
54
-
MyUniqueName.MyFunctions.performMyAction();
52
+
Sdk.attributeOnChange();
55
53
```
56
54
57
-
If you call a function within another function you can use the this keyword as a shortcut to the object that contains both functions. However, if your function is being used as an event handler, the this keyword will refer to the object that the event is occurring on.
55
+
If you call a function within another function, you can use this keyword as a shortcut to the object that contains both functions. However, if your function is being used as an event handler, this keyword will refer to the object that the event is occurring on.
58
56
59
57
## Avoid using unsupported methods
60
58
@@ -73,4 +71,4 @@ If you decide to use the remaining capabilities of jQuery that are useful with m
73
71
74
72
## Write your code for multiple browsers
75
73
76
-
Model-driven apps support multiple browsers. You should make sure that any scripts that you use will work with all supported browsers. Most of the significant differences between Internet Explorer and other browser have to do with HTML and XML DOM manipulation. Because HTML DOM manipulation is not supported, if script logic is only performing supported actions and using the [Xrm object model](understand-clientapi-object-model.md), the changes required to support other browsers could be small.
74
+
Model-driven apps support multiple browsers. Make sure that any scripts that you use will work with all supported browsers. Most of the significant differences between Internet Explorer and other browser have to do with HTML and XML DOM manipulation. Because HTML DOM manipulation is not supported, if script logic is only performing supported actions and using the [Xrm object model](understand-clientapi-object-model.md), the changes required to support other browsers could be small.
0 commit comments