blockify()

Creates global variables and when the returned code is executed via eval() the global variables will be deleted and will only be included in the block in which eval() executes.

This function is valid in v2.21.0 to v2.23.0. This function has been downloaded 7 times.

Parameters

{Object} obj
The object whose values should be added to the block's scope.
{Array|Function|RegExp|*=} opt_filter Optional, Default:undefined
If not given then all values will be setup to be added to the block's scope. If this is an array, only the matching keys found in the array will be setup to be added to the block's scope. If this is a function then it will iterate over all of the values in obj and will be passed (1) the value, (2) the key, (3) obj and the return value will be coerced to a boolean to determine if the key-value pair should be setup to be added to the block's scope. If this is a regular expression then only the keys that match will be setup to be added to the block's scope. In all other cases, all key-value pairs will be added as long as the key isn't this value.
{boolean=} opt_overwrite Optional, Default:true
Defaults to true. If true whenever eval() is called on the returned string any variables that could possibly be overwritten will be overwritten.

Returns

{string}
The JavaScript code that can be called by eval() to add the desired variables to the current scope.

Required Functions

This function directly requires the following functions which are included automatically:

  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.
  • isValidVarName()
    Determines if a string can be used as a variable name in JavaScript.
  • nativeType()
    Gets the native type name of a primitive or an object. Unlike YourJS.typeOf(), the types are solely determined by the system.