Skip to content

Instantly share code, notes, and snippets.

@man27382210
Last active May 13, 2016 08:44
Show Gist options
  • Save man27382210/2eb878c5b01366c4e11d8704118c0b3c to your computer and use it in GitHub Desktop.
Save man27382210/2eb878c5b01366c4e11d8704118c0b3c to your computer and use it in GitHub Desktop.
/*
* The following code snippet runs in an angular controller body.
* It tries to convert a blob object "data" into data URL and bind the result to the scope.
* Fix it so that $scope.data will make UI change as expected.
*/
/* global angular, data, FileReader */
angular.module('xxx').controller('Ctrl', ['$scope', function ($scope) {
var reader = new FileReader();
reader.onload = function (event) {
$scope.data = event.target.result;
};
reader.readAsDataURL(data);
}]);
/*
* Please describe different of bind, call, apply.
*/
/*
* Fix the following code snippet to make it work.
* You can only modify line 7.
* (Assume that <div id="page1"></div> exists)
*/
var g = document.getElementById;
g('page1').innerHTML = 'Hello World!';
/*
* Discuss the possible console output results for this code snippet.
* The "doSomething" function accepts a callback function as the input argument,
* but whether it is synchronus or asynchronus remains unknown.
*/
/* global doSomething */
console.log('hello 1');
setTimeout(function () {
console.log('hello 2');
}, 1);
console.log('hello 3');
doSomething(function (result) {
console.log('doSomething done');
});
setTimeout(function () {
console.log('hello 4');
}, 0);
console.log('hello 5');
/*
* Please describe different of React.js, Angular.js.
* Which one you will choice.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment