```
var postorderTraversal = function(root) {
var stack = [];
var values = [];
if (root)
stack.push(root);
while(stack.length > 0) {
var node = stack.pop();
values.unshift(node.val);
if (node.left)
stack.push(node.left);
if (node.right)
stack.push(node.right);
}
return values;
};
```