MCPcopy
hub / github.com/jquery/jquery / access

Function access

test/data/jquery-3.7.1.js:3881–3938  ·  view source on GitHub ↗
( elems, fn, key, value, chainable, emptyGet, raw )

Source from the content-addressed store, hash-verified

3879// Multifunctional method to get and set values of a collection
3880// The value/s can optionally be executed if it's a function
3881var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
3882 var i = 0,
3883 len = elems.length,
3884 bulk = key == null;
3885
3886 // Sets many values
3887 if ( toType( key ) === "object" ) {
3888 chainable = true;
3889 for ( i in key ) {
3890 access( elems, fn, i, key[ i ], true, emptyGet, raw );
3891 }
3892
3893 // Sets one value
3894 } else if ( value !== undefined ) {
3895 chainable = true;
3896
3897 if ( !isFunction( value ) ) {
3898 raw = true;
3899 }
3900
3901 if ( bulk ) {
3902
3903 // Bulk operations run against the entire set
3904 if ( raw ) {
3905 fn.call( elems, value );
3906 fn = null;
3907
3908 // ...except when executing function values
3909 } else {
3910 bulk = fn;
3911 fn = function( elem, _key, value ) {
3912 return bulk.call( jQuery( elem ), value );
3913 };
3914 }
3915 }
3916
3917 if ( fn ) {
3918 for ( ; i < len; i++ ) {
3919 fn(
3920 elems[ i ], key, raw ?
3921 value :
3922 value.call( elems[ i ], i, fn( elems[ i ], key ) )
3923 );
3924 }
3925 }
3926 }
3927
3928 if ( chainable ) {
3929 return elems;
3930 }
3931
3932 // Gets
3933 if ( bulk ) {
3934 return fn.call( elems );
3935 }
3936
3937 return len ? fn( elems[ 0 ], key ) : emptyGet;
3938};

Callers 1

jquery-3.7.1.jsFile · 0.70

Calls 4

isFunctionFunction · 0.85
toTypeFunction · 0.70
jQueryFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected