Skip to content

Commit 0fcf4f2

Browse files
authored
Merge pull request #3594 from MicrosoftDocs/Nava_clientapi
Updating best practice
2 parents d27b7a6 + ebc0bdd commit 0fcf4f2

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

powerapps-docs/developer/model-driven-apps/clientapi/client-scripting-best-practices.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ search.app:
1717
---
1818
# Best practices: Client scripting in model-driven apps
1919

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.
2121

2222
## Define unique JavaScript function names
2323

@@ -26,35 +26,33 @@ When you write functions that will be used in JavaScript libraries, your functio
2626
- **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.
2727
```JavaScript
2828
function MyUniqueName_performMyAction()
29-
{
30-
// Code to perform your action.
31-
}
29+
{
30+
// Code to perform your action.
31+
}
3232
```
3333
- **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.
3434
```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);
4947
```
5048

5149
Then when you use your function you can specify the full name. The following example shows this.
5250

5351
```JavaScript
54-
MyUniqueName.MyFunctions.performMyAction();
52+
Sdk.attributeOnChange();
5553
```
5654

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.
5856

5957
## Avoid using unsupported methods
6058

@@ -73,4 +71,4 @@ If you decide to use the remaining capabilities of jQuery that are useful with m
7371

7472
## Write your code for multiple browsers
7573

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

Comments
 (0)