x is a variable which, because it is scoped outside of the function that has been assigned to y.z, is accessible inside of y.z
What is going on in that code is that y is initialized to a new class of type 'w', then x is getting set to a reference to the current 'z' function, which is a member of the instance 'y' of class 'w'. Then, function 'z' is getting replaced by a new function, which calls doOneThing, and then executes the value of 'x', which as has already been established is the previous value of 'y.z', therefore, the new y.z extends the behavior of the old y.z by simple calling the old y.z before it returns.
I hope that makes sense.
Of course, given that you do say that the 'y' object doesn't have a 'z' member, than x will be undefined, and a runtime error will be thrown when you try to execute x().