var

private(set) with let properties - 'private(set)' modifier cannot be applied to read-only properties

邮差的信 提交于 2020-04-17 22:07:45
问题 I'm already aware of how private(set) works. But the below code is give compile-time error, class Person { private(set) let name: String //Error. private(set) let age: Int //Error. init(name: String, age: Int){ self.name = name self.age = age } } Error: 'private(set)' modifier cannot be applied to read-only properties Since name and age are not read-only properties, it shouldn't give such an error. If I use let instead of var , it is working fine. Just trying to know why? 回答1: private(set)

JS 窗口加载与定时器笔记

拈花ヽ惹草 提交于 2020-04-08 11:39:52
bom浏览器对象模型 bom由一系列相关的对象构成并且每个对象都提供了很多方法属性 bom顶级对象是window bom是浏览器产商在各自浏览器上定义的,兼容性差 window具有双重角色,他是一个全局对象.定义在全局作用域中的变量、函数都会变成window对象的属性和方法,但是在调用的时候可以省略window 窗口加载事件 window.onload当前页面文档加载完成后会触发该事件,在页面中只能写一次,如果有多个就以最后一个为准 可以换成window.addEventListener('load',function(){})则没有限制 如果网页中图片特别多可以用document.addEventListener('DOMContentLoaded',function(){}) DOMContentLoaded是DOM加载完毕,不包含图片,falsh,css等就可以执行 加载速度比load快一些 1 <button>点击</button> 2 window.onload = function () { 3 var btn = window.document.querySelector('button') 4 btn.onclick = function () { 5 alert('ok') 6 } 7 } 8 window.addEventListener('load',

一个相当酷的js图片展示网站

余生颓废 提交于 2020-04-08 00:59:39
在站酷上搜到一个相当酷的js图片展示网站 http://preview.zcool.com.cn/code/js/04/1/ 更酷的是,页面里包含全部的js代码!wow!!!!!!!!!!保存下面的代码,自己放上几张图试下,绝对效果超赞。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/html4/strict.dtd "> <html> <head> <title>1</title> <meta http-equiv="imagetoolbar" content="no"> <style type="text/css"> html { overflow: hidden; } body { margin: 0px; padding: 0px; background: #000; width: 100%; height: 100%; } #imageFlow { position: absolute; width: 100%; height: 80%; left: 0%; top: 10%; background: #000; } #imageFlow .diapo { position: absolute; left: -1000px; cursor: pointer; -ms

简单的图片翻页

∥☆過路亽.° 提交于 2020-04-08 00:57:41
1 function animatePic(){ 2 var box=$(".list-img"); 3 var item=box.find(".item-img"); 4 var left; 5 var len=item.length; 6 var _w=item.width(); 7 var w=_w*len; 8 var num=2; 9 $(".list-img").width(_w*len); 10 $(".next").click(function(){ 11 left=box.position().left; 12 if(left<=(w-_w*num)*-1) return false; 13 if(!box.is(":animated")){ 14 box.animate({left:"-="+_w},500); 15 } 16 }); 17 $(".prev").click(function(){ 18 left=box.position().left; 19 if(left>=0) return false; 20 if(!box.is(":animated")){ 21 box.animate({left:"+="+_w},500); 22 } 23 }); 24 $(".box-img .item-img").click(function(){ 25

js 增删节点

你。 提交于 2020-04-08 00:54:21
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>增加Table行</title> </head> <script language="javascript">// Example: obj = findObj("image1"); function findObj(theObj, theDoc){ var p, i, foundObj; if(!theDoc) theDoc = document; if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) { theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p); } if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for(i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0;

简单的Promise

强颜欢笑 提交于 2020-04-07 21:51:57
function MYPromise(fn) { var self = this self.onResolvedCallback = [] function resolve(value) { setTimeout(() => { self.data = value self.onResolvedCallback.forEach(callback => callback(value)) }) } fn(resolve) } MYPromise.prototype.then = function (fn) { var self = this return new MYPromise(resolve => { self.onResolvedCallback.push(function () { var result = fn(self.data) if (result instanceof MYPromise) { result.then(resolve) } else { resolve(result) } }) }) }    参考文章: https://juejin.im/post/5e6f4579f265da576429a907#heading-0 来源: https://www.cnblogs.com/shen076/p/12655996.html

apply-call-bind

怎甘沉沦 提交于 2020-04-07 21:48:54
call: var foo ={ value:1 } function bar(name,age) { console.log(this.value); console.log(name); console.log(age); } //bar.call(foo,'gongtao',11); Function.prototype.call2 = function (context) { var args = []; for (var i = 1, len = arguments.length; i < len; i++) { args.push(arguments[i]); } context.fn = this; context.fn(...args); delete context.fn; } bar.call2(foo,'gongtao',111); apply: var foo = { value: 1 } function bar(name, age) { console.log(this.value); console.log(name); console.log(age); } //bar.apply(foo); Function.prototype.apply2 = function (context, arr) { var context = context ||

nodejs 定时访问网页

和自甴很熟 提交于 2020-04-07 21:13:38
/** * Created by Administrator on 2018/2/25 0025. */ var https = require('http'); var schedule = require('node-schedule'); var rule = new schedule.RecurrenceRule(); // rule.second = [0,10,20,30,40,50];//隔十秒 // rule.hour =0;rule.minute =0;rule.second =0;//每天0点执行 rule.minute = [0,20,40];//每小时的0分钟,20分钟,40分钟执行 var j = schedule.scheduleJob(rule, function(){ httpGet(); console.log('现在时间:',new Date()); }); function httpGet() { var uri = "http://baidu.com" https.get(uri, function (res) { console.log("状态码: " + res.statusCode); }) } 来源: 51CTO 作者: IT阿飞 链接: https://blog.51cto.com/itafei/2087042

Js完成ListBox内容的交互实例

空扰寡人 提交于 2020-04-07 20:27:12
这几天在做一个关于大学排名的网站,其中遇到了上图中的问题,需向某个对象中添加新的学校群体,这就用到了 ListBox,而要进行两个ListBox之间的交互,无疑有两个办法:一个是在服务器端与客户端不停的PostBack,这无疑会大大降低效率。这是就体现出JavaScript在客户端的优势。下面介绍一下,又不足的地方希望大家指出! 下面是JS代码:用四个函数分别对应四个按钮,完成该功能。 < script type = " text/javascript " > function SelectAll() { var lst1 = window.document.getElementById( " <%=lb_Sourse.ClientID %> " ); var length = lst1.options.length; var string = window.document.getElementById( " <%=hf_NewName.ClientID %> " ) for (var i = 0 ;i < length;i ++ ) { var v = lst1.options[i].value; var t = lst1.options[i].text; var lst2 = window.document.getElementById( " <%=lb_NewName

ajax及模态框

折月煮酒 提交于 2020-04-07 20:23:16
//修改 $("#eventList").on("click",".btn-edit",function () { var _id = $(this).parent().data("id"); var model_id = $("#resBox").find(".list-modal").find(".actt").data("id"); var _data = { id: _id, model_id : model_id }; ModifyRecord({ title: "编辑记录", html: __inline("./content/userUpdate.html"), callback: function(box){ var _box = box.find("#confirm"); $.ajax({ url: api.configfiledetail, data: { id : _id, model_id :model_id, }, type: 'get', dataType: 'json', success: function(data){ data1 = data; _box.find("." +fie+"+ ").val(data+"."+" + fie + "); var form = $("#formModel",parent.document); var