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

Function access

dist-module/jquery.module.js:827–884  ·  view source on GitHub ↗
( elems, fn, key, value, chainable, emptyGet, raw )

Source from the content-addressed store, hash-verified

825// Multifunctional method to get and set values of a collection
826// The value/s can optionally be executed if it's a function
827function access( elems, fn, key, value, chainable, emptyGet, raw ) {
828 var i = 0,
829 len = elems.length,
830 bulk = key == null;
831
832 // Sets many values
833 if ( toType( key ) === "object" ) {
834 chainable = true;
835 for ( i in key ) {
836 access( elems, fn, i, key[ i ], true, emptyGet, raw );
837 }
838
839 // Sets one value
840 } else if ( value !== undefined ) {
841 chainable = true;
842
843 if ( typeof value !== "function" ) {
844 raw = true;
845 }
846
847 if ( bulk ) {
848
849 // Bulk operations run against the entire set
850 if ( raw ) {
851 fn.call( elems, value );
852 fn = null;
853
854 // ...except when executing function values
855 } else {
856 bulk = fn;
857 fn = function( elem, _key, value ) {
858 return bulk.call( jQuery( elem ), value );
859 };
860 }
861 }
862
863 if ( fn ) {
864 for ( ; i < len; i++ ) {
865 fn(
866 elems[ i ], key, raw ?
867 value :
868 value.call( elems[ i ], i, fn( elems[ i ], key ) )
869 );
870 }
871 }
872 }
873
874 if ( chainable ) {
875 return elems;
876 }
877
878 // Gets
879 if ( bulk ) {
880 return fn.call( elems );
881 }
882
883 return len ? fn( elems[ 0 ], key ) : emptyGet;
884}

Callers 1

jQueryFactoryFunction · 0.70

Calls 3

toTypeFunction · 0.70
jQueryFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected