Use === for comparing typeof to undefined (it's probably not super necessary but let's just simplify things by removing possible corner cases).
Return self.api rather than api.