Created
June 27, 2012 22:17
-
-
Save pangratz/3007220 to your computer and use it in GitHub Desktop.
Replace Undefined with string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//original ember version | |
Ember.getPath = function(root, path) { | |
var hasThis, isGlobal, ret; | |
// Helpers that operate with 'this' within an #each | |
if (path === '') { | |
return root; | |
} | |
if (!path && 'string'===typeof root) { | |
path = root; | |
root = null; | |
} | |
path = cleanupStars(path); | |
// If there is no root and path is a key name, return that | |
// property from the global object. | |
// E.g. getPath('Ember') -> Ember | |
if (root === null && path.indexOf('.') < 0) { return get(window, path); } | |
// detect complicated paths and normalize them | |
path = normalizePath(path); | |
hasThis = HAS_THIS.test(path); | |
if (!root || hasThis) { | |
var tuple = normalizeTuple(root, path); | |
root = tuple[0]; | |
path = tuple[1]; | |
tuple.length = 0; | |
} | |
return getPath(root, path); | |
}; | |
var getPath = Ember.getPath; | |
// Overwrite the original and add the OMG 'feature' | |
// @pangratz solution | |
Ember.getPath = function(obj, path) { | |
var value = getPath(obj, path); | |
if (obj === App.objectWhichHasUndefinedProps) { | |
return (Ember.none(value) ? 'OMG %@ is not defined!!'.fmt(path) : value); | |
} | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be clear, you just have to add the part starting from line #36 to your code...