html's People
html's Issues
原型链
Stock.prototype = { //通过原型链实现
registerObserver: function(fn) { //函数及对象
this.funs.push(fn); //添加订阅者
},
removeObserver: function(fn) {
this.funs = this.funs.filter( //过滤函数
function(el) { //过滤条件
if (el !== fn) { //返回所以不是fn的观察者组成的数组
return el;
}
}
);
},
notifyObserver: function(newpic, thisObj) {
var scope = newpic;
this.funs.forEach(
function(el) {
// console.log(scope);
//console.log(el.sorc);
// var re =
// (el.sorc <= scope) ? el.show("我赚了:"+scope - el.sorc): el.show("我赔了:"el.sorc - scope)
if (scope >= el.sorc) {
var data = scope - el.sorc;
var str = "我赚了" + data;
el.show(str);
} else {
var data = el.sorc - scope;
var str = "我赔了" + data;
el.show(str);
}
}
);
}
}
用assign去代替直接赋值给prototype是不是好点,感觉直接赋值会把原来的原型链给破坏掉
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.