1.What is encapsulation, and what do functions encapsulate?
Encapsulation is hide the data and methods in single unit from outside world. To access the data and methods we need to create instance of that class and access that data through public data members which are declared in that class.
2.What is a pure function?
The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information that may change as program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices.
Examples:
3.A recursive function, must have some sort of an end condition. Why would we get a "out of stack space" error message if a recursive function does not have an end condition?
A Recursive function is function which call itself during execution.This enables the function to repeat itself several times, outputting the result and the end of each iteration. In every function call the local variables, result of that each call is saved temprary in Stack and when get the end condition that saved values is reuse for that next procedure of that function. But, when end condition will not met the stack data could not be pop, else local veriable will push continuously in stack and because of no way to emapty the stack when stack will get full the error message will ocur.
4.What is object augmentation, and how do we do it?
In JavaScript, you can add methods to individual objects without the need for additional classes. This has enormous power because you can write far fewer classes and the classes you do write can be much simpler. Recall that JavaScript objects are like hashtables. You can add new values at any time. If the value is a function, then it becomes a method.
So in the example above, I didn't need a Parenizor class at all. I could have simply modified my instance.
We added a toString method to our myParenizor instance without using any form of inheritance. We can evolve individual instances because the language is class-free.
Encapsulation is hide the data and methods in single unit from outside world. To access the data and methods we need to create instance of that class and access that data through public data members which are declared in that class.
2.What is a pure function?
The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information that may change as program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices.
Examples:
sin(x)
, returning the sine of a number xlength(s)
, returning the size of a string s3.A recursive function, must have some sort of an end condition. Why would we get a "out of stack space" error message if a recursive function does not have an end condition?
A Recursive function is function which call itself during execution.This enables the function to repeat itself several times, outputting the result and the end of each iteration. In every function call the local variables, result of that each call is saved temprary in Stack and when get the end condition that saved values is reuse for that next procedure of that function. But, when end condition will not met the stack data could not be pop, else local veriable will push continuously in stack and because of no way to emapty the stack when stack will get full the error message will ocur.
4.What is object augmentation, and how do we do it?
In JavaScript, you can add methods to individual objects without the need for additional classes. This has enormous power because you can write far fewer classes and the classes you do write can be much simpler. Recall that JavaScript objects are like hashtables. You can add new values at any time. If the value is a function, then it becomes a method.
So in the example above, I didn't need a Parenizor class at all. I could have simply modified my instance.
myParenizor = new Parenizor(0); myParenizor.toString = function () { if (this.getValue()) { return this.uber('toString'); } return "-0-"; }; myString = myParenizor.toString();
We added a toString method to our myParenizor instance without using any form of inheritance. We can evolve individual instances because the language is class-free.