http://knockoutjs.com/
<user-bio> <h3>Richard</h3> <img src="img/richard_profile.jpg" alt="Richard's profile picture"> <p>Before working at NNN, Richard... </user-bio>
ソフトウェアエンジニアの技術ブログ:Software engineer tech blog
随机应变 ABCD: Always Be Coding and … : хороший
http://knockoutjs.com/
<user-bio> <h3>Richard</h3> <img src="img/richard_profile.jpg" alt="Richard's profile picture"> <p>Before working at NNN, Richard... </user-bio>
$('#my-elem').click(function(e){ //the element has been clicked.. do stuff })
document.body.innerHTML = ”;
document.body.style.background= “white”;
var num = [1, 2, 3];
for(var i = 0; i < nums.length; i++){ var num = nums[i]; var elem = document.createElement('div'); elem.textContent = num; elem.addEventListener('click', function(){ alert(num); }); document.body.appendChild(elem); } [/javascript] [javascript] getCurrentCat: function(){ return model.currentCat; }, getCats: function(){ return model.cats; }, setCurrentCat: function(cat){ model.currentCat = cat; }, incrementCounter: function(){ model.currentCat.clickCount++; catView.render(); } }; [/javascript]
function loadImage(src, parent, callback){ var img = document.createElement('img'); img.src = src; img.onload = callback; parent.appendChild(img); };
var sequence = get('example.json') .then(doSomething) .then(doSomethingElse);
Syntax
var promise = new Promise(function(resolve[, reject]){ var value = doSomething(); if (thingWorked){ resolve(value); } else if (somethingWentWrong){ reject(); } }).then(function(value) { return nextTing(value); }).catch(rejectFunction);
function setup() { document.getElementById('canvas').addEventListener('mousemove',onMouseMove); document.getElementById('canvas').addEventListener('keydown',onKeyDown); } function onMouseMove(event) { var posx = event.clientX; var posy = event.clientY; console.log("(", posx, ", ", posy, ")"); } function onKeyDown(event) { var keyID = event.keyID; console.log("ID: ", keyID); }
javascript test library
https://jasmine.github.io/
describe('Address Book', function(){ it('should be able to add a contact', function(){ var addressBook = new AddressBook(), thisContact = new Contact(); addressBook.addContact(thisContact); expect(addressBook.getContact(0)).toBe(thisContact); }); });
describe('Address Book', function(){ it('should be able to add a contact', function(){ var addressBook = new AddressBook(), thisContact = new Contact(); addressBook.addContact(thisContact); expect(addressBook.getContact(0)).toBe(thisContact); }); it('should be able to delete a contact', function(){ var addressBook = new AddressBook(), thisContact = new Contact(); addressBook.addContact(thisContact); addressBook.deleteContact(0); expect(addressBook.getContact(0)).not.toBeDefine(); }); });
var amy = {loc:1}; move(amy); var ben = {loc:9}; move(ven);
var move = function(car){ car.loc++; };
var gold = {a:1}; var blue = extend({}, gold); var rose = Object.create(gold); gold.z = 3 log(blue.z); //undefined log(rose.z); //3
var = {}
this indicate in memory variable.
npm install gulp-sass
var gulp = require('gulp'); gulp.task('default', function(){ console.log("hello, gulp!"); }); gulp.task('styles', function(){ gulp.src('sass/**/*.scss') .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest('./css')); }); gulp.task('default', function(){ gulp.watch('sass/**/*.scss',['styles']); });
Linting is the process of running a program that will analyse code for potential errors.
ESLint
[vagrant@localhost rss24]$ sudo npm install -g eslint
span:inline
div:block
parameter
?name=value
fragment
#fragment
function inName(name){ name = name.trim().split(" "); name[1] = name[1].toUpperCase(); name[0] = name[0].slice(0,1).toUpperCase() + name[0].slice(1).toLowerCase(); return name[0] + " "+name[1]; }
JavaScript Object Notation. JSON is a popular and simple format for storing and transferring nested or hierarchal data. It’s so popular that most other programming languages have libraries capable of parsing and writing JSON (like Python’s JSON library). Internet GET and POST requests frequently pass data in JSON format. JSON allows for objects (or data of other types) to be easily encapsulated within other objects.
var education = { "scool": [ { "name": "Echerd College", "city": "Saint Petersburg, FL, US", "degree": "BA", "major": ["compSci", "French"] }, { "name": "Nova Southeastern University", "city": "Fort Lauderdale, FL, US", "degree": "Masters", "major": ["compSci"] }, ] };
validate json : http://jsonlint.com/
if (document.getElementsByClassName("education-entry").length === 0) { document.getElementById("education").style.display = "none"; }
for in loop
for(item in object){ console.log(contry); }
click
$(document).click(function(loc){ var x = loc.pageX; var y = loc.pageY; logClicks(x,y); });
var work = { "jobs": [ { "employer": "Udacity", "title": "Course Developer", "location": "Mountain View, CA", "dates": "Feb 2014 - Current", "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg." }, { "employer": "LearnBIG", "title": "Software Engineer", "location": "Seattle, WA", "dates": "May 2013 - Jan 2014", "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg." }, { "employer": "LEAD Academy Charter High School", "title": "Science Teacher", "location": "Nashville, TN", "dates": "Jul 2012 - May 2013", "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg." }, { "employer": "Stratford High School", "title": "Science Teacher", "location": "Nashville, TN", "dates": "Jun 2009 - Jun 2012", "description": "Who moved my cheese cheesy feet cauliflower cheese. Queso taleggio when the cheese comes out everybody's happy airedale ricotta cheese and wine paneer camembert de normandie. Swiss mozzarella cheese slices feta fromage frais airedale swiss cheesecake. Hard cheese blue castello halloumi parmesan say cheese stinking bishop jarlsberg." } ] }; // Your code goes here! Let me help you get started function locationizer(work_obj) { var locationArray = []; for(job in work_obj.jobs){ var newLocation = work_obj.jobs[job].location; locationArray.push(newLocation); } return locationArray; }