Babban matsalar Get bazuwar boolean shine rashin tsaro. Duk wanda ke da damar shiga uwar garken zai iya samar da ฦimar boolean na sabani.
var randomBoolean = Math.random() >= 0.5;
Wannan layin lambar yana ba da ฦimar boolean bazuwar zuwa madaidaicin โrandomBooleanโ. ฦimar boolean ko dai gaskiya ne ko ฦarya, kuma aikin Math.random() ne ya samar dashi. Wannan aikin yana dawo da lambar bazuwar tsakanin 0 da 1, kuma idan wannan lambar ta fi ko daidai da 0.5, to ฦimar boolean zata zama gaskiya. In ba haka ba, zai zama ฦarya.
Menene aji
?
Aji a JavaScript samfuri ne don ฦirฦirar abubuwa.
Fadada Darasi
ฦarfafa azuzuwan sifa ce ta JavaScript wanda ke ba ku damar ฦirฦirar azuzuwan al'ada waษanda za a iya amfani da su a cikin lambar ku. Wannan na iya zama da amfani idan kuna buฦatar ฦirฦirar nau'in al'ada ko kuma idan kuna buฦatar ฦara takamaiman ayyuka zuwa nau'in da ke akwai.
Don ฦirฦirar ฦarin aji a JavaScript, da farko kuna buฦatar ฦirฦirar sabon fayil mai suna extend.js kuma ฦara lambar mai zuwa:
var MyClass = aiki (){}; MyClass.prototype = {}; MyClass.extend = aiki (sauran){wannan.prototype = other.prototype; };
Na gaba, kuna buฦatar ayyana kaddarorin da hanyoyin sabon ajin ku. Kuna yin haka ta ฦara kaddarori da hanyoyi zuwa abin samfurin MyClass. Ga misali:
MyClass.prototype._myMethod = aiki(){}; MyClass.prototype._anotherMethod = aiki(){}; MyClass.extend ({_myMethod: aiki(){}, _anotherMethod: aiki(){}});
A ฦarshe, kuna buฦatar yin rajistar sabon ajin ku tare da mai tara JavaScript ta ฦara layin da ke gaba zuwa lambar ku:
MyClass._register = aiki(){};