-
Notifications
You must be signed in to change notification settings - Fork 6
/
2WayDataBinding.js
33 lines (31 loc) · 1.03 KB
/
2WayDataBinding.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Created by Namita Malik on 26/3/15.
*/
/*
* I am here polluting the global object by making $scope as global scope variable, but this for the testing purpose
* and sake of simplicity so that I can test from terminal
* */
var $scope = {};
(function () {
var bindClasses = ["name", "age"];
var attachEvent = function (classNames) {
classNames.forEach(function (className) {
var elements = document.getElementsByClassName(className);
for (var index in elements) {
elements[index].onkeyup = function () {
for (var index in elements) {
elements[index].value = this.value;
}
}
}
Object.defineProperty($scope, className, {
set: function (newValue) {
for (var index in elements) {
elements[index].value = newValue;
}
}
});
});
};
attachEvent(bindClasses);
})();