Posts

Showing posts with the label javascript

Javascript Event Oriented Programming example on SPSocialFeed

SPSocialFeed is the sharepoint microblog, where you can post your thoughts and reply on yourself and other. We wanted to add some functionalities for every reply and post added, so i used the new  "MutationObserver" and "CustomEvent"  new API's in ES6 to create an event-full way to implement solution // batman is the man in-charge catching the bad guys in the night. // so now he catches the good events in the feed let batman = ( function (){ let config = { childList : true }; let batman = class batman{ constructor(){ this .v = "2.0.0" ; //register call to batCave fn. to _spBodyOnLoadFunctionNames, the SP onready _spBodyOnLoadFunctionNames.push( 'batman.batCave' ); } batCave(){ let feed = document.getElementById( 'ms-feedthreadsdiv' ); //childNodes can be any type of nodes, like text node. children is only HTML...

Javascript Expost Interface Implementation

For some time i've been thinking, how can i export a JS object that will expose only public functions, yet will keep all my million functions "hidden" just to make it less messy.. The point is to create an anonymous function and create the instance within, while returning a new object with members pointing at the instance functions with ".bind" to the instance. So here it is let encapsulated = ( function encapsulated_builder(){ let encapsulated = class encapsulated{ constructor(){ this .food = 'bamba' ; this .animal = 'lion' ; } addFood(f){ this .food += ' ' + f; } addFoodByAnimal(a){ switch (a){ case 'dog' : this .addFood( 'bone' ); break ; case 'cat' : this .addFood( 'fish' ); break ; } } addAnimal(a){ this .animal += ' ' + a; this .addFoodByAnimal(a); } printFood(){ ...

Javascript sort then by

i'll just give a piece of code to show this Great Answer . var a = []; for (x = 1; x <= 3; x++){ for (y = 1; y <= 3; y++){ for (z = 1; z <= 3; z++){ a.push({x:x, y:y, z:z}) } } } a a.sort(function (a, b) {     return a.z - b.z || a.x - b.x || a.y - b.y ; }); just copy paste into the console and see for yourself. for strings you'll need extra help var a = []; for (x = 1; x <= 3; x++){ for (y = 1; y <= 3; y++){ for (z = 1; z <= 3; z++){ a.push({x:x, y:y, z:'af' + z.toString()}) } } } var strSort = function(a,b){ if(a < b) return -1;     if(a > b) return 1;     return 0; } a.sort(function (a, b) { return strSort(a.z,b.z) || a.x - b.x || a.y - b.y ; });

JAVASCRIPT בסיס בעיברית

Image
אנא הסתכלו על השגיאה הזו פה למטה, ואני מאוד מבקש מכל מי שלא יכול לאמר לי בדיוק מה השגיאה רק מהסתכלות על התמונה הזו שיקרא בעיון את המייל הזה והדוגמא שלו. אז אם אתה אחד מאותם חברים יקרים שרוצה ללמוד, אנא פתח במקביל את ה JSBIN הזה שהכנתי במיוחד, ובצד ימין אפשר ללחוץ על הכפתורים clear ואח"כ run כדי להריץ מחדש, וכן כולם מוזמנים לערוך, זה לא יצור גרסה חדשה לכולם אלא מקומית לכל אחד http://jsbin.com/fusuyanoje/2/edit?js,console רקע בסיסי – JS זה שפה שבין היתר מבוססת SCOPE , כלומר כל אובייקט ופונקציה זה SCOPE משל עצמו, שמהווה CHILD ל SCOPE  שמעליו, כאשר הגלובלי, ה ROOT SCOPE , הוא ה WINDOW . חלק מהמנגון הזה אומר ש child scope כאשר הוא מחפש איזה פרמטר/פונקציה אם הוא לא מוצא את זה אצלו הוא יחפש אותו אצל אבא שלו, סבא שלו, סבא רבא וכו'. אז אם נלך לדוגמא שלנו אנו רואים פרמטר בשם globalVar שמוגדר ב ROOT , מה שנקרא גלובלי, ולאורך כל הדרך, בכל מקום בעולם שנחפש אותו אנו תמיד נמצא אותו. לאחר מכן יש לנו פונקציה (וכל פונקיצה היא אובייקט וכל אובייקט הוא פונ...