jQuery.scope()
Categories: Utilities
jQuery.scope( scope, [ context ] )Returns: Object
Plugin: jQuery.scope
Description: Get an object from a scope string.
-
jQuery.scope( scope, [ context ] )
version added: 1.0scope An object path in dot noatation.
context An object as context for the object path.
The jQuery.scope()
method returns the object which was selcted with the scope string,
if the object doesn't exists it is created by jQuery.scope()
.
If no context is defined, the context is the window object. It's are very usefull method to prevent errors if you are not sure whether the object already exists.
-
Get a simply scope.
Code:
$.extends( $.scope('jQuery.newPlugin.example'), { foo: 'bar' }); $.scope('newPlugin.example', $ ); // results: {foo: 'bar'} $.scope('newPlugin.example', $ ); // results: {foo: 'bar'} jQuery.newPlugin.example.foo // results: 'bar' $.scope('jQuery.newPlugin.example').foo // results: 'bar'