大体思路(六)
本节内容:
一、生命周期的钩子函数的实现
  ==》 callHook(vm , 'beforeCreate')
  beforeCreate 实例创建之后 事件数据还未创建
二、初始化initState
  ==>initState(vm) // 初始化数据
    ==> initProps(vm,opts.props) 待续
    ==> initMethods 待续
    ==> initComputed 待续
    ==> if data initData else { observer(vm._data={},true)}
      initData
        ==> getData(data,vm) 如果是一个函数直接调用这个函数
        ==> data methods props 里面属性名称不能相同
        ==> proxy(vm,data,key) 双向数据绑定的地方 defineProperty(vm,key,sharedProperty)
        ==> sharedProperty // 公共访问器对象
vue.js代码如下
  1. // 大体思路(六)
  2. // 本节内容:
  3. // 生命周期的钩子函数的实现
  4. // ==》 callHook(vm , 'befroeCreate')
  5. // beforeCreate 实例创建之后 事件数据还未创建
  6. // ==>initState(vm) // 初始化数据
  7. // ==> initProps(vm,opts.props) 待续
  8. // ==> initMethods 待续
  9. // ==> initComputed 待续
  10. // ==> if data initData else { observer(vm._data={},true)}
  11. // initData
  12. // ==> getData(data,vm) 如果是一个函数直接调用这个函数
  13. // ==> data methods props 里面属性名称不能相同
  14. // ==> proxy(vm,data,key) 双向数据绑定的地方 defineProperty(vm,key,sharedProperty)
  15. // ==> sharedProperty // 公共访问器对象
  16. // 响应式系统
  17.  
  18. (function(global,factory){
  19. // 兼容 cmd
  20. typeof exports === 'object' && module !== 'undefined' ? module.exports = factory():
  21. // Amd
  22. typeof define === 'function' && define.amd ? define(factory) : global.Vue = factory();
  23. })(this,function(){
  24. var uip = 0;
  25. function warn(string){
  26. console.error('Vue Wran:' + string)
  27. }
  28. function warnNonpresent(target,key){
  29. warn('属性方法'+ key + '未在实例对象上定义,渲染功能正在尝试访问这个不存在的属性!')
  30. }
  31. function resolveConstructorOptions(Con){
  32. var options = Con.options;
  33. // 判断是否为vm的实例 或者是子类
  34. return options
  35. }
  36. var hasOwnPropeerty = Object.prototype.hasOwnProperty
  37. function hasOwn(obj , key){
  38. return hasOwnPropeerty.call(obj,key)
  39. }
  40. function makeMap(str, expectsLoweraseC){
  41. if(expectsLoweraseC){
  42. str = str.toLowerCase()
  43. }
  44. var map = Object.create(null)
  45. var list = str.split(',')
  46. for(var i = 0 ; i < list.length; i++){
  47. map[list[i]] = true
  48. }
  49. return function(key){
  50. return map[key]
  51.  
  52. }
  53. }
  54. var isbuiltInTag = makeMap('slot,component',true)
  55. var isHTMLTag = makeMap(
  56. 'html,body,base,head,link,meta,style,title,' +
  57. 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
  58. 'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
  59. 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
  60. 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
  61. 'embed,object,param,source,canvas,script,noscript,del,ins,' +
  62. 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
  63. 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
  64. 'output,progress,select,textarea,' +
  65. 'details,dialog,menu,menuitem,summary,' +
  66. 'content,element,shadow,template,blockquote,iframe,tfoot'
  67. );
  68. var isSVG = makeMap(
  69. 'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +
  70. 'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
  71. 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',
  72. true
  73. );
  74. var ASSET_TYPES = [
  75. 'component',
  76. 'directive',
  77. 'filter'
  78. ];
  79.  
  80. var LIFECYCLE_HOOKS = [
  81. 'beforeCreate',
  82. 'created',
  83. 'beforeMount',
  84. 'mounted',
  85. 'beforeUpdate',
  86. 'updated',
  87. 'beforeDestroy',
  88. 'destroyed',
  89. 'activated',
  90. 'deactivated',
  91. 'errorCaptured'
  92. ];
  93. var noop = function (){}
  94. var isReservedTag = function(key){
  95. return isHTMLTag(key) || isSVG(key)
  96. }
  97. // 检测data的属性名称是否为 _ 或者$ 开始的,这些的话是vue的其他属性的值。
  98. function isReserved(key) {
  99. var c = key.charCodeAt(0)
  100. return c === 0x24 || c === 0x5F
  101. }
  102. function validataComponentName(key){
  103. //检测component 的自定义名称是否合格
  104. // 只能是字母开头或下划线,必须是字母开头
  105. if(!(/^[a-zA-Z][\w-]*$/g.test(key))){
  106. warn('组件的名称必须是字母或中横线,必须由字母开头')
  107. }
  108. // 1. 不能为内置对象,2.不能是html ,和avg的内部标签
  109. if( isbuiltInTag(key) || isReservedTag(key)){
  110. warn('不能为html标签或者avg的内部标签')
  111. }
  112. }
  113. function checkComonpents(child){
  114. for(var key in child.components){
  115. validataComponentName(key)
  116. }
  117. }
  118. // 配置对象
  119. var config = {
  120. // 自定义的策略
  121. optionMergeStrategies:{}
  122. }
  123. var strats = config.optionMergeStrategies
  124. strats.el = function(parent,child , key , vm){
  125.  
  126. if(!vm){
  127. warn('选项'+key+'只能在vue实例用使用')
  128. }
  129. return defaultStrat(parent,child , key , vm)
  130. }
  131. function mergeData(to,form){
  132. // 终极合并
  133. if(!form){
  134. return to
  135. }
  136. // 具体合并。
  137. }
  138. function mergeDataorFn(parentVal,childVal,vm){
  139. // 合并 parentVal childVal 都是函数
  140. if(!vm){
  141. if(!childVal){
  142. return parentVal
  143. }
  144. if(!parentVal){
  145. return childVal
  146. }
  147. return function mergeDataFn(parentVal,childVal,vm){//只是一个函数 什么样的情况下调用 加入响应式系统
  148. // 合并子组件对应的data 和 父组件对应的data
  149. return mergeData(
  150. typeof parentVal === 'function' ? parentVal.call(this,this) : parentVal, // -----忘记写
  151. typeof childVal === 'function' ? childVal.call(this,this): childVal) // -----忘记写
  152. }
  153. }else{ // vue实例
  154. return function mergeInstanceDataFn(){//只是一个函数 什么样的情况下调用 加入响应式系统
  155. var InstanceData = typeof childVal === 'function' ? childVal.call(vm,vm): childVal; // -----忘记写
  156. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm,vm): parentVal; // -----忘记写
  157. if(InstanceData){
  158. return mergeData(InstanceData,defaultData)
  159. }else{ // -----忘记写
  160. return defaultData
  161. }
  162.  
  163. }
  164. }
  165. }
  166. strats.data = function(parent,child , key , vm){
  167. if(!vm){
  168. // console.log(typeof child === 'function')
  169. if(child && !(typeof child === 'function')){
  170. warn('data必须返回是一个function')
  171. }
  172. return mergeDataorFn(parent,child)
  173. }
  174. return mergeDataorFn(parent,child,vm)
  175. }
  176. // 生命周期策略的合并,值等于一个function 如果是有两个,放到一个数组里面。
  177. function mergeHook(parentVal,childVal,key,vm){
  178. // console.log(key)
  179. // console.log(parentVal.concat(childVal) )
  180. return childVal ? parentVal ? parentVal.concat(childVal):
  181. Array.isArray(childVal) ? childVal : [childVal] : parentVal
  182. }
  183. LIFECYCLE_HOOKS.forEach(function(key){
  184. strats[key] = mergeHook
  185. });
  186. // 检测是否为object
  187. function isPlainObject(obj){
  188. return Object.prototype.toString.call(obj) === '[object Object]'
  189. }
  190. function assetObjectType(obj){
  191. if(!isPlainObject(obj)){
  192. warn('选项的值'+obj+'无效:必须是一个对象的')
  193. }
  194. }
  195. // 对parent实现链式调用。
  196. function extend(to,form){
  197. for(key in form){
  198.  
  199. to[key] = form[key]
  200. }
  201. return to
  202. }
  203. // 实现Assets 的策略合并 conmponents filter diretive
  204. function mergeAssets(parentVal,childVal,key,vm){
  205. var parent = Object.create(parentVal || null) // 保证子类的每个值的指向都是一个新的object。否则回出现相互引用的现象。
  206. if(childVal){
  207. assetObjectType(childVal)
  208. return extend(parent,childVal)
  209. }
  210. return parent
  211. }
  212. ASSET_TYPES.forEach(function(key){
  213. strats[key+'s'] = mergeAssets
  214. })
  215. // 实现watch的策略和并,将相同的属性放到一个数组里面。
  216. strats.watch = function(parentVal,childVal , key , vm){
  217. if(!childVal){
  218. return Object.create(parentVal)
  219. }
  220. var res = {}
  221. res = extend(res,parentVal)
  222. for(var key in childVal){
  223. var parent = res[key]
  224. var child = childVal[key]
  225. res[key] = parent ? Array.isArray(parent) ? parent.concat(child) : [parent].concat(child) :
  226. Array.isArray(child) ? child : [child] ;
  227. }
  228. return res
  229. }
  230. // 实现props指令的合并策略
  231. strats.props = function(parentVal,childVal , key , vm){
  232. if(!childVal){
  233. return parentVal
  234. }
  235. var res = Object.create( null)
  236. extend(res,parentVal)
  237. if(childVal){
  238. extend(res,childVal)
  239. }
  240. return res
  241. }
  242. function defaultStrat(parent,child , key , vm){
  243. return child === undefined ? parent :child ;
  244. }
  245. var cmalizeRE = /-(\w)/g
  246. function camelize(val){
  247. return val.replace(cmalizeRE,function(c,m){
  248. return m ? m.toUpperCase(): ""
  249. })
  250. }
  251. function normalizeProps(options){
  252. var props = options.props
  253. if(!props){
  254. return
  255. }
  256. var i , val , name
  257. var res = {}
  258. if(Array.isArray(props)){
  259. i = props.length
  260. while(i--){
  261. val = props[i]
  262. if(toString.call(val) === '[object String]'){
  263. name = camelize(val)
  264. res[name] = {type: null}
  265. }else{
  266. warn('使用数组愈发时props成员' +val+ '必须时一个数组')
  267. }
  268.  
  269. }
  270. }else if(isPlainObject(props)){
  271. for(var key in props){
  272. val = props[key]
  273. name = camelize(key)
  274. res[name] = isPlainObject(val) ? val : {type: val}
  275. }
  276. }else {
  277. warn('选项props的值必须是一个对象或者是数组')
  278. }
  279. options.props = res
  280. }
  281. function mormalizeDirectives(options){
  282. var dir = options.directives
  283. var res = {}
  284. if(!dir){
  285. return
  286. }
  287. if(dir){
  288. for(var key in dir){
  289. var val = dir[key]
  290. var name = camelize(key)
  291. if(isPlainObject(val)){
  292. res[name] = val
  293. }
  294. if(toString.call(val) === '[object Function]'){
  295. res[name] = {
  296. bind: val,
  297. upata: val
  298. }
  299. }
  300. }
  301. }
  302. options.directives = res
  303.  
  304. }
  305. function mergeOptions(parent,child,vm){
  306. var options = {}
  307. // 检测是component 是否是合法的
  308. checkComonpents(child)
  309. // 规范props
  310. normalizeProps(child)
  311. // 规范 dirctives
  312. mormalizeDirectives(child)
  313.  
  314. // console.log(parent, child)
  315. for(key in parent){
  316. magerField(key)
  317. }
  318. for(key in child){
  319. if(!hasOwn(parent ,key)){ // parent 中循环过地方不进行循环
  320. magerField(key) // ----忘记写
  321. }
  322.  
  323. }
  324. // 默认合并策略
  325. function magerField(key){
  326. // 自定义策略 默认策略
  327. // console.log(key)
  328. var result = strats[key] || defaultStrat // ---忘记写
  329. options[key] = result(parent[key],child[key] , key , vm)
  330. }
  331. // console.log(options)
  332. return options
  333. }
  334.  
  335. var allowedGlobals = makeMap(
  336. 'Infinity,undefined,NaN,isFinite,isNaN,' +
  337. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  338. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  339. 'require' // for Webpack/Browserify
  340. );
  341. function isNative(Ctor){
  342. return typeof Ctor !== undefined && /native code/.test(toString.call(Ctor))
  343. }
  344. var hasproxy = typeof Proxy !== undefined && isNative(Proxy)
  345. var hasHeadler = {
  346. has: function(target,key){
  347. var val = key in target
  348. // key 是否是全局对象 或者内置方法 _
  349. var isAllowed = allowedGlobals(key) || (typeof key === 'string' && key.charAt(0) === '_')
  350. if(!val && !isAllowed){
  351. warnNonpresent(target,key)
  352. }
  353. return val || !isAllowed
  354. }
  355. }
  356. var getHeadler = {
  357. get: function(target,key){
  358. if( typeof key === 'string' && !(key in target)){
  359. warnNonpresent(target,key)
  360. }
  361. return target[key]
  362. }
  363. }
  364.  
  365. // 数据代理
  366. function initProxy(vm){
  367. var options = vm.$options
  368. // 判断是否是es6 是否存在Proxy
  369. if(hasproxy){
  370. // 渲染函数拦截那些操作。 1. has 查询 2. get 或者
  371. var headler = options.render && options.render._withStripeed ?
  372. getHeadler:
  373. hasHeadler;
  374. vm._renderPorxy= new proxy(vm,headler)
  375. }else{
  376. // 如果不支es6 Proxy
  377. vm._renderPorxy = vm
  378. }
  379. }
  380.  
  381. // 初始化当前实例的$children 和$parent 的指向
  382. function initLifeCycle(vm){
  383. var options = vm.$options
  384. // 当前组件 父实例
  385. var parent = options.parent // 组件的实例对象
  386. // 是否抽象组件
  387. if(parent && !parent.abstrat){
  388. while(parent.$options.abstrat && parent.$parent){
  389. parent = parent.$options.parent
  390. }
  391. parent.$children.push(vm)
  392. }
  393. vm.$parent = parent
  394. vm.$root = parent ? parent.$root : vm;
  395.  
  396. vm.$children = [];
  397. vm.$refs = {};
  398.  
  399. vm._watcher = null;
  400. vm._inactive = null;
  401. vm._directInactive = false;
  402. vm._isMounted = false; // 是否挂载
  403. vm._isDestroyed = false; // 是否销毁
  404. vm._isBeingDestroyed = false; // 是否正在销毁
  405.  
  406. }
  407. function callHook(vm,hook){
  408. var options = vm.$options
  409. var obj = options[hook]
  410. if(obj){
  411. for(var i =0 ; i < obj.length ; i++){
  412. obj[i].call(vm)
  413. }
  414. }
  415.  
  416. }
  417. function getData(data,vm){
  418. return data.call(vm,vm)
  419. }
  420.  
  421. //共享的访问器对象
  422. var sharedProperty = {
  423. enumerable:true,
  424. configurable:true,
  425. get:noop,
  426. set:noop
  427. };
  428. function proxy(vm,data,key){
  429.  
  430. sharedProperty.get = function(){
  431. console.log("我监听到你访问了我")
  432. return this[data][key]
  433. },
  434. sharedProperty.set =function(newVal){
  435. console.log("我设置了data的值"+key+"==" +newVal)
  436. this[data][key] = newVal
  437.  
  438. }
  439. Object.defineProperty(vm,key,sharedProperty)
  440. }
  441. function initData(vm){
  442. var opts = vm.$options
  443. var data = vm.$options.data
  444. // 通过之前strats 里面合成好的数据,data是一个function ,为了独立数据调用的空间。拿到data的值。
  445. data = vm._data = typeof data === 'function' ? getData(data,vm) : data || {}
  446. if(!isPlainObject(data)){
  447. data = {}
  448. warn('data选项应该是object对象')
  449. }
  450. // data methods props 里面属性名称不能相同
  451. var props = opts.props
  452. var methods = opts.methods
  453. for(let key in data){
  454. if(props && hasOwn(props,key)){
  455. warn("props " + key + "选项已经定义为data的属性.")
  456. }else if(methods && hasOwn(methods,key)){
  457. warn("methods: " + key + "选项已经定义为data的属性.")
  458. }else if(!isReserved(key)){
  459. proxy(vm,"_data",key)
  460. }
  461.  
  462. }
  463.  
  464. }
  465. function observer(){
  466. // 相应试系统
  467. }
  468. function initState(vm){
  469. var opts = vm.$options
  470. // 初始化props
  471. if(opts.props){
  472. initProps(vm,opts.props)
  473. }
  474. // 初始化methods
  475. if(opts.methods){
  476. initMethods(vm,opts.methods)
  477. }
  478. // 初始化computed
  479. if(opts.computed){
  480. initComputed(vm,opts.computed)
  481. }
  482. // 初始化data 如果存在就initData
  483. if(opts.data ){
  484. initData(vm)
  485. }else{
  486. // 放在响应式系统里面
  487. observer(vm._data={},true)
  488. }
  489. }
  490. function initMinxin(options){
  491. Vue.prototype._init = function(options){
  492. var vm = this
  493. // 记录生成的vue实例对象
  494. vm._uip = uip++ // //-------忘记写
  495. //合并选项
  496. vm.$options =mergeOptions(resolveConstructorOptions(vm.constructor),options,vm)
  497. // // 初始化数值代理
  498. initProxy(vm)
  499. // 初始化当前实例的$children 和$parent 的指向
  500. initLifeCycle(vm)
  501. // 调用beforeCreate 的钩子函数
  502. callHook(vm, 'beforeCreate')
  503. // 初始化数据
  504. initState(vm)
  505. }
  506. }
  507. function Vue(options){
  508. // 安全机制
  509. if(!(this instanceof Vue)){ //-------忘记写
  510. warn('Vue是一个构造函数,必须是由new关键字调用')
  511. }
  512. this._init(options)
  513. }
  514. initMinxin() // 初始化选项1: 规范 2: 合并策略。
  515. Vue.options = {
  516. components: {
  517. transtions: {},
  518. keepAlive:{},
  519. solt:{},
  520. transtionsGroup:{}
  521. },
  522. directives:{},
  523. _bash: Vue
  524. }
  525. function initExend(Vue){
  526. Vue.extend = function(extendOptions){
  527. extendOptions = extendOptions || {} // -----忘记写
  528. var Super = this
  529. var Child = function VueComponent(options) {
  530. this._init(options)
  531. }
  532. Child.prototype = Object.create(Super.prototype)
  533. Child.prototype.constructor = Child // 改变constructor 的指向
  534. Child.options = mergeOptions(Super.options,extendOptions)
  535. // 子类继承父类的静态方法。
  536. Child.extend = Vue.extend
  537. // console.log(new Child({}))
  538. return Child
  539. }
  540. }
  541. initExend(Vue)
  542. return Vue
  543. })

dome.html 代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>第五课</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <huml></huml>
  12. </div>
  13. <script src="vue.js"></script>
  14. <!-- <script src="vue2.5.1.js"></script> -->
  15. <script type="text/javascript">
  16. var componentA = {
  17. el: "#app"
  18. }
  19. var vm = new Vue({
  20. el:"#app",
  21. data: {
  22. message: "hello Vue",
  23. key: "wodow",
  24. test: 1
  25. },
  26. beforeCreate: function(){
  27. console.log('我钩子函数beforeCreate')
  28. },
  29. components:{
  30. humle: componentA
  31. }
  32.  
  33. })
  34.  
  35. vm.test = 2;
  36. console.log(vm)
  37. </script>
  38. </body>
  39. </html>

【js】vue 2.5.1 源码学习 (七) 初始化之 initState 响应式系统基本思路的更多相关文章

  1. 如何实现全屏遮罩(附Vue.extend和el-message源码学习)

    [Vue]如何实现全屏遮罩(附Vue.extend和el-message源码学习) 在做个人项目的时候需要做一个类似于电子相册浏览的控件,实现过程中首先要实现全局遮罩,结合自己的思路并阅读了(饿了么) ...

  2. 【js】 vue 2.5.1 源码学习(五) props directives规范化 props 合并策略

    大体思路 (四) 上节回顾: A: 对于生命周期函数将父子组件的函数放到一个数组里面,特定时间点调用,保证父子组件函数都调用到. B: 对于directive,filters,components 等 ...

  3. 【js】vue 2.5.1 源码学习 (四) 钩子函数 资源选项 watch 的合并策略

    大体思路 (三)    1.钩子函数 自定义策略       LIFECYCLE_HOOKS= []      created = [function(){} , function(){}] 组装方法 ...

  4. 【js】vue 2.5.1 源码学习 (三) Vue.extend 和 data的合并策略

    大体思路 (三)  1. 子类父类  2.Vue.extend()      //创建vue的子类 组件的语法器 Vue.extend(options) Profile().$mount('#app' ...

  5. 【js】vue 2.5.1 源码学习 (十) $mount 挂载函数的实现

    大体思路(九) 本节内容: 1. $mount 挂载函数的实现. // 将Vue.prototype.$mount 缓存下来 ==>mountComponet(this,el) { // 组建挂 ...

  6. 【js】vue 2.5.1 源码学习 (九) 响应数组对象的变

    大体思路(八) 本节内容: 1.Observe 如何响应数组的变化 代理原型 数组变异方法 shell cacheArrProto methods 新添加的数组需要加到显示系统里面,拦截 push等的 ...

  7. 【js】Vue 2.5.1 源码学习 (八)响应式入口observe

    大体思路(七) 本节内容: deps 依赖收集的数组对象 => Dep 构造函数 /** ==> observe() * var ob * ==> if --isObject * = ...

  8. 【js】 vue 2.5.1 源码学习(六) initProxy initLifeCycle 渲染函数的作用域代理

    大体思路 (五) 1. initProxy 渲染函数的作用域代理 ==> es6 如果支持proxy (hasProxy) 就用proxy 不支持就用 defineProperty() prox ...

  9. Vue源码学习02 初始化模块init.js

    接上篇,我们看到了VUE分了很多模块(initMixin()stateMixin()eventsMixin()lifecycleMixin()renderMixin()),通过使用Mixin模式,都是 ...

随机推荐

  1. DOM的利用冒泡做的一个小程序

    我们都知道DOM的事件流,有冒泡事件,如何有效的利用冒泡? 优化:应该尽量少的添加事件监听:原理:每添加一个事件监听事件,就会在浏览器中添加一个EventListener,如果数量过多,浏览器只能一个 ...

  2. GNU的__builtin_popcount函数

    用来计算32位的unsigned int中的1的个数, 其内部实现是根据查表法来计算的.

  3. RapidMiner Studio 入门

    http://docs.rapidminer.com/studio/getting-started/ RapidMiner Studio 入门 FEIFEI MA 2015-12-07RAPIDMIN ...

  4. 【JZOJ4935】【NOIP2017GDKOI模拟1.12】b

    Boring 构造一棵包含1号结点的连通子集个数刚好为给定的n的树. 这棵树的结点不能多于60. 1<=n<=109 Gai 容易得到,计算给定一棵树的Ans1,其中Ansi表示包含i号结 ...

  5. facebook第三方登录

    一:创建和配置开发者应用 https://developers.facebook.com 登录开发者(可能要手机验证,身份证严重)->创建应用(web )->填写配置,网站网址和应用域名需 ...

  6. JavaScript —— 给函数参数设置默认值

    一.ES5 function fn(x, y){ y = y || 20; console.log(x, y); } fn(); // undefined 20 fn(5); // 5 20 fn(5 ...

  7. 【Mysql的那些事】数据库之ORM操作

    1:ORM的基础操作(必会) <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(* ...

  8. Python学习之路7☞装饰器

    一:命名空间与作用域 1.1命名空间 局部命名空间: def foo(): x=1 def func(): pass 全局命名空间: import time class ClassName:pass ...

  9. 尖峰7月线上技术分享--Hadoop、MySQL

      7月2号晚20:30-22:30 东大博士Dasight分享主题<大数据与Hadoop漫谈> 7月5号晚20:30-22:30  原支付宝MySQL首席DBA分享主题<MySQL ...

  10. oralce where字句的用法

    ?       如何显示工资高于3000的员工 select * from emp where sal>3000; ?       如何查找1982.1.1后入职的员工 select * fro ...