exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 3 question 31 discussion

Actual exam question from Microsoft's 70-480
Question #: 31
Topic #: 3
[All 70-480 Questions]

DRAG DROP -
You are developing a shared library to format information. The library contains a method named _private.
The _private method must never be called directly from outside of the shared library.
You need to implement an API for the shared library.
How should you complete the relevant code? (Develop the solution by selecting the required code segments and arranging them in the correct order. You may not need all of the code segments.)
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
Note:

* Here there is a basic example:
// our constructor
function Person(name, age){
this.name = name;
this.age = age;
};
// prototype assignment
Person.prototype = (function(){
// we have a scope for private stuff
// created once and not for every instance
function toString(){
return this.name + " is " + this.age;
};
// create the prototype and return them
return {
// never forget the constructor ...
constructor:Person,
// "magic" toString method
toString:function(){
// call private toString method
return toString.call(this);
}
};
})();
* Example:
You can simulate private methods like this:
function Restaurant() {
}
Restaurant.prototype = (function() {
var private_stuff = function() {
// Private code here
};
return {
constructor:Restaurant,
use_restroom:function() {
private_stuff();
}
};
})();
var r = new Restaurant();
// This will work:
r.use_restroom();
// This will cause an error:
r.private_stuff();

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Etnic
Highly Voted 5 years, 6 months ago
Why is there this._private? Where is _private declared? I think there should be var _private, but I am not sure...please for explanation.
upvoted 5 times
KyryIx
5 years, 3 months ago
I agree to you. Because "this" permit access to method.
upvoted 1 times
...
...
JftCoCo
Most Recent 5 years ago
I think the answer is function getFormatter() { var _private = function (data) {return custom(input)}; this.parseValue = function(input) { return _private(input); } }
upvoted 3 times
nelaed
4 years, 10 months ago
I think the same.
upvoted 1 times
...
...
MFDOOM
5 years, 2 months ago
When creating a constructor, and you are adding a 'method' to it ,you do not have to declare the variable separately first i.e _private.You can create it on the fly such as the following : function CreateNames (name){ this.name = name this._private = function getName () { console.log(`You created a new name`); } } If _private was a property and not a method , then yes, the variable declaration would be necessary before using the _private.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...