如何修复以下错误

How to fix the following errors

我实现了 spectrum color picker,我正在尝试修复 JSLint 错误。我有 2 种类型的错误,我似乎无法修复。以下是错误:

  • Unexpected '~'
  • Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.

这是第一个错误的代码:

function contains(str, substr) {
    return !!~('' + str).indexOf(substr);
}

第二个错误代码:

var hasTouch = ('ontouchstart' in window);
function contains(str, substr) {
    return str.indexOf(substr) !== -1;
}

var hasTouch = window.ontouchstart !== undefined;