Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHARED: The Working Background Of The $ In Jquery
#1
Hello nctists I know many of us may know this but for those who don't, It was some months ago when I started playing with JavaScript again that I decided to build something like JQuery Big Grin though the project has been abandoned I want to however share a little secret Big Grin

JQuery uses the $ object which acts as a function when intended and as an object as well.

Code:
$('body').html(); // $ working as a function which return an object
$.ajax(); // $ acting as an object


Now there are many ways of doing this but I'll be sharing only one Big Grin

Code:
var myObjFunc = function(){/*this does nothing*/}?function(){/*This is called*/ return "Who"; }:{}
myObjFunc(); //returns Who
myObjFunc; //returns myObjFunc() as a string
myObjFunc.x; //returns the value of key x


Hope this helps someone Big Grin

@dealwap,@deelino,@hackinubee,@dynamo,@devHammed,@cheatex and @laive come in Big Grin
[-] The following 2 users Like jonath45's post:
  • cheatex, Hackinubee
#2
JavaScript functions are just Objects in disguise. below is a basic breakdown of jQuery. $ is just a variable pointing to jQuery() function object. Now in JavaScript, creating a variable pointing to an Object will not clone it but instead be an alias to it (unlike Strings, Number etc) so making changes to $ variable will also affect jQuery.

PHP Code:
function jQueryselectorcontext ) {
  
// parse selector here
  
return {
    
els: [], // array of elements parsed above
    
html: function( ) {
      
// returns innerHTML of the first element if 'c' is not passed else set innerHTML of all the elements
      
if ( ! ) {
        return 
this.els[0].innerHTML;
      }
      
this.els.forEach( function( el ) {
        
el.innerHTML c;
      } );
    },
  };
}
jQuery.ajax = function( urloptions ) {
  
// ...
}

window.$ = jQuery

[-] The following 1 user Likes devHammed's post:
  • jonath45
Reply
#3
(09-22-2018, 06:43 AM)devHammed Wrote:
JavaScript functions are just Objects in disguise. below is a basic breakdown of jQuery. $ is just a variable pointing to jQuery() function object. Now in JavaScript, creating a variable pointing to an Object will not clone it but instead be an alias to it (unlike Strings, Number etc) so making changes to $ variable will also affect jQuery.

PHP Code:
function jQueryselectorcontext ) {
  
// parse selector here
  
return {
    
els: [], // array of elements parsed above
    
html: function( ) {
      
// returns innerHTML of the first element if 'c' is not passed else set innerHTML of all the elements
      
if ( ! ) {
        return 
this.els[0].innerHTML;
      }
      
this.els.forEach( function( el ) {
        
el.innerHTML c;
      } );
    },
  };
}
jQuery.ajax = function( urloptions ) {
  
// ...
}

window.$ = jQuery



wonderful one bro Big Grin this though longer is also a beautiful way to get the job done
[-] The following 1 user Likes jonath45's post:
  • devHammed
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  HELP: Please Help Me With Good Working Media Query To Hide Pc Content From Mobile rocklife22 2 106 09-26-2017, 08:07 PM
Last Post: Deelino
  HELP: Javascript Vs Jquery. beme 10 488 08-21-2017, 07:20 AM
Last Post: beme
  HELP: Why Is This Code Not Working. Webmasters Check In! Thepreditor 6 307 08-16-2017, 09:26 PM
Last Post: jonath45
  I Need Help With This JQuery Code maximus 6 350 01-04-2017, 06:12 PM
Last Post: maximus
  SHARED: Trim Your Long Text With Jquery Using Javascript Strict bfaschat 1 296 12-03-2016, 08:20 PM
Last Post: dealwap
  SHARED: 100% Working Styled Like Button ryanmontana 0 230 11-06-2016, 03:32 PM
Last Post: ryanmontana
  Angularjs Vs Jquery – What Are The Major Differences? Devman 1 616 11-01-2016, 06:04 PM
Last Post: dealwap
  Autocomplete Search System Using Php, Jquery dealwap 1 321 09-22-2016, 01:57 PM
Last Post: rocklife22
  HELP: Working Exloader Needed For Wapka Oluwatimilehin Oduneye 10 1,058 07-28-2016, 08:30 AM
Last Post: tjhenry
  HELP: I Need Working Way On How To Block Source Coder On Wapka iamnetboy 2 525 07-07-2016, 02:41 PM
Last Post: Hackinubee



Users browsing this thread: 1 Guest(s)

About Nigeria's Creative Talents

Nigeria's Creative Talents is an online community where every creative Nigerians can share ideas with themselves.

For any more information, please use our contact form.

              User Links

              Advertise