2016-10-12 曹强
状态模式的关键是区分事物内部的状态,事物内部状态的改变往往会带来事物的行为改变。 电灯程序 首先给一个不用状态模式的电灯程序例子: var Light = function() { this.state = 'off'; //电灯初始状态off this.button = null; //电灯开关按钮 }; Light.prototype.init = function() { var button = document.createElement('button'), self = this; button.innerHTML = '开关'; this.button = document. 继续阅读 »
2015-09-11 biezhi
```java public class ProgressBar { private double finishPoint; private double barLength; public ProgressBar(){ this.finishPoint = 100; this.barLength = 20; } public ProgressBar(double finishPoint, int barLength){ this.finishPoint = finishPoint; this.barLength = barLength; } /** * 显示进度条 * @p 继续阅读 »
2015-04-06 Alex Sun
this.props 在React中,可以通过this.props来传递参数,看下面的例子: ```javascript var OuterComponent = React.createClass({ render: function(){ return ( This is a message first message second message 继续阅读 »
2015-04-19 Jason Liao
从一个视频里接触到 JavaScript 的get和set 一般来说,我们是怎么给我们类的属性定义get和set方法的呢 ```javascript var Person = function (age) { this.age = age; }; Person.prototype = { getAge: function () { return this.age; }, setAge: function (age) { this.age = age; } }; var p1 = new Person(19); var p2 = new Person(23); ``` 继续阅读 »
2016-07-31 曹强
原型链继承 让构造函数的原型对象等于另一个类型的实例,利用原型让一个引用类型继承另一个引用类型的属性和方法 ``` function SuperType() { this.property=true; } SuperType.prototype.getSuperValue=function(){ return this.property; }; function SubType() { this.subProperty=false; } //继承SuperType SubType.prototype=new SuperType(); SubType.prototype.getSubValue=f 继续阅读 »
2018-04-03 LEo
这是一个系列文章,主要分享shell(部分功能仅适用于bash)的使用建议和技巧,每次分享3点,希望你能有所收获。 另外,这些建议和技巧都是我工作中用到的,只有我用到了才会记录并分享出来,所以没有什么顺序而言,用到什么我就分享什么。 1 sed替换文件内容 $ cat demo this is demo $ sed -i s/demo/test/g demo $ cat demo this is test 通过sed,可以很方便替换文件中的某些字符串。比如这里的demo文件只有一行内容:this is demo。通过sed将文件中的demo字符串替换成test。这里的-i选项是直接修改文件内容,字母s表示替换字符,字母g 继续阅读 »
2015-04-18 Alex Sun
render 在使用React.createClass创建一个组件类的时候,必须要提供一个render方法,其它的生命周期相关方法是可选的。 当组件的render方法被调用的时候,它会检查this.props和this.state,然后返回一个单独的子元素。所谓一个单独的子元素,即最外层只能是一个元素,无论它内部有多少层嵌套,例如下面的例子就是错误的: 继续阅读 »
2015-07-31 jude
阅读前,希望你了解javascript的原型链 P.js 项目地址 基础用法: var Animal = P(function(animal){ animal.init = function(name){ this.name = name; }; animal.move = function(meters){ console.log(this.name + " moved " + meters + " m."); } }); 继续阅读 »
2017-01-20 Oliver Wang
一般情况下,textarea 的高度是定死的,rows 指定了之后,高度就不变了,内容多了之后会出现滚动条,这样的设定在大部分的场景下面是够用的, 但是有时就会很丑陋(废话😊)。 我们都知道 HTML 的元素都有一个 scrollHeight 这个属性,就是当该元素出现滚动条的时候,内容的高度。 那就方便了: js $(".weui-textarea").on('input propertychange keyup',function () { $(this).height(this.scrollHeight); }); 这样就实现了高度自动增加的 Textarea,但当我试着删掉几行,想让它自动降低高度的时候不禁菊花 继续阅读 »
2015-11-27 Oliver Wang
直接写 js function imgError(image) { image.onerror = null; // prevent event bubble image.src = "/images/noimage.gif"; return true; } html 使用 jQuery ```js $("img").error(function () { $(this).unbind("error").attr("src", "broken.gif"); }); //If you use this technique you can use the "one" method to av 继续阅读 »