-
Notifications
You must be signed in to change notification settings - Fork 56
$.live()
The $.live() function is made to toggle a function when a value changes in an array. This function was largely inspired by the Object.prototype.watch() function that isn't available for all modern browsers 😊. So, it simply works by watching all element in an array.
window variable. That's why the push method's live implementation doesn't work with window
This function will take 2 arguments: $.live(watched, callback). The callback will have 4 arguments: callback(obj, prop, newVal, oldVal)
Now, let's create an array that, when modified, will tell the modified value. (Yes, I know that this have no useful purpose, except maybe if you're dealing with security 🚨 stuff.)
JS:
// declaring the dog object
var dog = {"cute": "yep!", "dangerous": false};
// Creating the function that will tell modified value
$.live(dog, function(obj, prop, newVal, oldVal){ console.log("dog was modified, "+ prop +" was "+oldVal+" and has been set to "+newVal) });
// Testing
dog.cute = "nop!"
dog.dangerous = true;
Don't hesitate to ask your questions
- Home
- The Core Languages
- Getting Started: Installation
- The Basics (
$.var()+$.target()) - Developing for DisplayJS
-
$.select()- Text related
- If...else
$.xss()$.repeat()$.custom()$.live()$.load()$.on()$.onEvent()$.ready()- Scroll API
$.all()$.clone()$.is()$.valEmpty()$.remove()$.show()&$.hide()$.ajax()- Class Related
$.css()$.getStyle()- Fade effects
$.extend()$.dynamic()$.parent()- Elements-Nodes
$.component()$.time_ago()$.copy()$.then()$.sleep()$.getProp()